External Libraries Mac OS X

63 views
Skip to first unread message

Lindsey Mysse

unread,
Dec 21, 2010, 8:16:10 PM12/21/10
to Google SketchUp Developers - SketchUp Ruby API
I am trying to require 'socket' in a SU script with Mac OS X. I have
tried literal paths. I have tried $LOAD_PATH<<"Literal Value Here"
etc. etc.

What are you all doing? I really just need to open up a UDP port--
which is bonehead easy in IRB and Ruby. But I've been beating my head
against the wall for weeks now.

Thanks for your help!

Lindsey

morgan_greywolf

unread,
Dec 26, 2010, 9:51:29 AM12/26/10
to Google SketchUp Developers - SketchUp Ruby API
Hi, Lindsey! SketchUp ships with an embedded Ruby interpreter.
Normally, you can use functionality from the Ruby library by copying
the necessary .rb files into the Plugins folder, or into a
subdirectory off the Plugins folder. However, socket is a native C/C+
+ library, not Ruby. I'm not 100% sure, but there might be no way to
do it. If it <em>were</em> possible, you would have to copy socket.so
from /usr/lib/ruby/[platform]/socket.so into your Plugins folder, but
I doubt this will work.

Lindsey Mysse

unread,
Dec 29, 2010, 10:49:06 AM12/29/10
to sketch...@googlegroups.com

Thanks for that answer. I guess I have to take a different tack then.
Hmm.

I haven't played around with the c++ api yet. Maybe I should write my own little udp client there?

Has anyone worked with the c++ api? Will I run into any problems that way?

sent from my android.

On Dec 29, 2010 10:38 AM, "morgan_greywolf" <rob....@gmail.com> wrote:

On Dec 21, 8:16 pm, Lindsey Mysse <lindsey.my...@gmail.com> wrote: > I am trying to require 'socket'...

Hi, Lindsey!  SketchUp ships with an embedded Ruby interpreter.
Normally, you can use functionality from the Ruby library by copying
the necessary .rb files into the Plugins folder, or into a
subdirectory off the Plugins folder.  However, socket is a native C/C+
+ library, not Ruby.  I'm not 100% sure, but there might be no way to
do it.  If it <em>were</em> possible, you would have to copy socket.so
from /usr/lib/ruby/[platform]/socket.so into your Plugins folder, but
I doubt this will work.

-- You received this message because you are subscribed to the Google Groups "SketchUp Ruby API" g...

Rich Morin

unread,
Dec 29, 2010, 1:40:34 PM12/29/10
to sketch...@googlegroups.com
I don't know of a way to support sockets in SU. However,
I've been successful at creating a file-based proxy which
allows me to perform asynchronous communication to client
code running in a web browser (via WebSockets):

http://cfcl.com/twiki/bin/view/Projects/SketchUp/WD_WoR_BrowserDialog

I'm quite certain that the proxy could be modified to use
regular sockets, instead of WebSockets.


A totally different hack which I recently encountered (but
haven't played with) is to have JavaScript client code talk
to a remote server. The plugin then talks to the client in
SU's (ab)normal fashion: execute_script, location-'foo', etc.

-r
--
http://www.cfcl.com/rdm Rich Morin
http://www.cfcl.com/rdm/resume r...@cfcl.com
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Software system design, development, and documentation

Dan Rathbun

unread,
Dec 29, 2010, 11:52:35 PM12/29/10
to Google SketchUp Developers - SketchUp Ruby API


On Dec 21, 8:16 pm, Lindsey Mysse <lindsey.my...@gmail.com> wrote:
> I am trying to require 'socket' in a SU script with Mac OS X. I have
> tried literal paths. I have tried $LOAD_PATH<<"Literal Value Here"
> etc. etc.

See: http://forums.sketchucation.com/viewtopic.php?f=180&t=33759#p297087

Be sure that RUBY_PLATFORM is the same in both Sketchup Ruby and in
the OEM Ruby installed by Apple.
(If NOT, COPY, not rename, the entire OEM platform subdir, to a dir
named to the RUBY_PLATFORM value within Sketchup Ruby.)

You could try this for trouble shooting:

# global constant RUBY_ENGINE is available in Ruby 1.9 and up
Object.const_set(:RUBY_ENGINE,RUBY_VERSION.split('.')[0..1].join('.'))
if RUBY_VERSION<'1.9.0'
#
$LOAD_PATH<<"/usr/lib/ruby/#{RUBY_ENGINE}"
$LOAD_PATH<<"/usr/lib/ruby/#{RUBY_ENGINE}/#{RUBY_PLATFORM}"
#
begin
Kernel.require('socket') # use original require method
rescue LoadError => e
if e.message.include?('no such file to load')
UI.messagebox("The file 'socket' could not be found!\nCheck your
$LOAD_PATH array.\n")
end
stderr.write(e.message)
rescue
raise # pass up any other Exceptions
else
if Object.const_defined?(:Socket)
UI.messagebox("The file 'socket' was loaded.\nThe Socket class has
been defined.\n")
end
end
Reply all
Reply to author
Forward
0 new messages