SDK, optimization, and cross platform support
-
I am getting very interested in using the SketchUp SDK for the purpose of increasing the performance of my Ruby scripts. Problem is, I have very poor understanding of how the process of creating DLLs and interfacing them with Ruby code works.
I am not expecting a detailed description of how to get this to work but maybe someone could help point me in the right direction (online resources?) or at least answer some of these basic questions that I have:
- Is the SketchUp SDK incorpated from Ruby by creating DLLs and then calling them with the WIN32API? Is there another way? What is the equivalent method on Mac?
- How do you create a DLL or Mac equivalent? Is it simply a compiled CPP file that contains a class and associated methods? Or is it more complex? Where can I find some good reference material on creating DLLs that applies to Mac and PC?
- I don't have Visual C++. Do I need it for this sort of thing or is there another (free?) way?
- Is it relatively straightforward to function parameters back and forth between Ruby and the DLL? For example, I might want to send some SketchUp entities to a DLL (using Ruby) and then have the DLL do some heavy processing and then get the results back into Ruby. What is the process for this?
Thanks in advance!
-
@whaat said:
I have very poor understanding of how the process of creating DLLs and interfacing them with Ruby code works.
Sketchup SDK is a completely different thing from shared objects (.so) from Ruby.
also "Both the SkpReader and SkpWriter APIs were written prior to SketchUp's acquisition by Google. Neither API is under active development" (from here)
@whaat said:
- Is the SketchUp SDK incorpated from Ruby by creating DLLs and then calling them with the WIN32API? Is there another way? What is the equivalent method on Mac?
let's forget about Sketchup SDK and talk about .so
they are dynamic loaded library (.dll on win, .dylib on mac) that allows creating ruby objects in a different language. they will be seen in Ruby world as normal classes, methods, ... and there is no need of a Win32API or anything else. just pure ruby stuff - require and Class.new
@whaat said:
- How do you create a DLL or Mac equivalent? Is it simply a compiled CPP file that contains a class and associated methods? Or is it more complex? Where can I find some good reference material on creating DLLs that applies to Mac and PC?
see http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html
the idea is that you have a ruby 'config' file that will create a makefile that will create the dynamic library. it is easy and powerful (and "fun" to debug inside Sketchup)
it should work on both Mac/Pc with some tweaking of the makefile
@whaat said:
- I don't have Visual C++. Do I need it for this sort of thing or is there another (free?) way?
you can use gcc on Mac (comes with OS pre installed) and on PC you can use PellesC - this is what I use for Podium
@whaat said:
- Is it relatively straightforward to function parameters back and forth between Ruby and the DLL? For example, I might want to send some SketchUp entities to a DLL (using Ruby) and then have the DLL do some heavy processing and then get the results back into Ruby. What is the process for this?
you define a Ruby class in C world that does all the work and send back the results in whatever Ruby object you want (array, string, ...)
some things to remember:
- it is single task - if it takes a lot of time, SU UI will be blocked and white.
- don't mix native threads with Ruby threads
- watch out for function calls level - recursion will quickly end with a 'stack level too deep' error
- language functions can be destroyed by ruby garbage collection and end in no-man land and crash everything
- debug extensions out of Sketchup first, in normal Ruby - easier and faster to debug
- you will spend more time debugging than coding
-
Thanks so much TBD for your help! Much appreciated!
@unknownuser said:
let's forget about Sketchup SDK and talk about .so
OK, but I will need the functions in the SDK to do the processing. I need access to SketchUp entity information using C++. (eg. methods to determine the vertices of a given face) So I need the SDK, right? These are methods that I need a performance increse on.
Any advice on using the SDK?@unknownuser said:
- you will spend more time debugging than coding
Yes I fear this, especially as someone with so little experience in these matters.
-
@whaat said:
I need access to SketchUp entity information using C++. (eg. methods to determine the vertices of a given face) So I need the SDK, right?
yes. for that you will need Visual C++ (you can use other compilers but making it compilable is a big task and tiresome)
you can use skpreader to read the info and send it to your application. there is an example in the SDK that converts a skp to xml so you can use that for start.
also there is a undocumented bridge between SDK world and Ruby - see this
-
@unknownuser said:
see http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html
This link was quite useful in understanding your SUExt sample.
Got any link to further reading as to how you deal with other data types passes? How do you make a method that takes an array as argument (or hash) iterates it and return a new one?Is it possible to handle SU defined classes?
-
@thomthom said:
How do you make a method that takes an array as argument (or hash) iterates it and return a new one?
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html
Examples (in C,) dealing with arrays are given (although somewhat simple.) -
cheers!
Advertisement