DLL callback to ruby
-
aaaaaaaaaaah OK, now it's clear to me. I can see exactly what you mean and how this works.
Dan, thank you so much for your time to explain all this to me. I don't know how to thank you enough, and I wish I could return the favor, but you are obviously way above me that there is nothing you can learn from me. I realy appreciate it Dan.
Now I'm gonna go play.........
-
Dan, one last question, can the dll be compiled in 64bit or does it have to be 32bit like SK?
Does the handle return by rb_define_module('Sketchup') correspond to the ISkpApplication interface?
-
@alienizer said:
Dan, one last question, can the dll be compiled in 64bit or does it have to be 32bit like SK?
I would say 32bit, because the Ruby that Sketchup loads is also 32bit. There is a 64bit Ruby edition, but it may be in the 1.9.x branch, which Sketchup cannot load even 1.9.x 32bit.
@alienizer said:
Does the handle return by rb_define_module('Sketchup') correspond to the ISkpApplication interface?
I would say "not exactly". There may be some C++ methods from that interface, that are "Ruby wrapped" into the Sketchup module, as well as others from different C++ objects.
Getting a handle on the application object (and from there it's window object, and then it's UI element objects, and so on...) are methods that the current Ruby Sketchup module lacks. You'll have to use a C++ call, as shown in the SDK examples to get the app handle.
-
Thank Dan. So far, everything works great, I even got this to work...
modUI = rb_define_module('UI');
menu = rb_funcall(modUI, rb_intern('menu'), 0, nil);but I'm stuck on this one...
rb_funcall(menu, rb_intern('add_item'), 1, rb_str_new2('File/Testing'));
It tells me "tried to create Proc object without a block"
Where do you learn all this? I can't find any docs on rb_intern or what to pass to it. I only guess!
-
The API
add_item
method takes 2 args, aString
and aBlock
, ... not 1 arg. -
@dan rathbun said:
The API
add_item
method takes 2 args, aString
and aBlock
, ... not 1 arg.Indeed! I figured it out, and the
rb_intern('menu')
takes one, a str of the submenu name, like "Plugins" right?When I do
rb_intern('add_submenu')
with 1 arg of str "Testing", it adds only "T" to the Pluigns menu, the first letter only!?If I don't use rb_str_new2 SK crash, Am I doing it right?
For the Block, do I have to use rb_something to pass the Block, or just the reference pointer?
Sorry to be a pain in the......
-
@alienizer said:
I can't find any docs on rb_intern or what to pass to it.
At the bottom of the "Extending Ruby" chapter, of the "Pick-Axe" book:
@unknownuser said:*ID rb_intern(char name")
Returns an ID for a given name. If the name does not exist, a symbol table entry will be created for it.
I just pasted an example that used the rb_intern to create an ID... not sure if it's really needed. You can try just passing a normal string, as the method name argument.
(Using rb_intern on the C-side, is the same as using a Symbol on the Ruby side, thus:
:test_item
or"test_item".intern
or"test_item".to_sym
What are the arguments, for ruby C-side functions, generally?
The list at the bottom of the "Extending Ruby" chapter, is not complete, AND that edition was written for Ruby circa 1.6.x (so it's out of date.)
For a definitive list, refer to to the function prototypes, in the Ruby C source folder:
%(#000000)[**.../include/ruby-*<version>*/ruby/ruby.h**]
.. so if your using Ruby ver 1.8.6, the path would be:
%(#000000)[**.../include/ruby-1.8.6/ruby/ruby.h**]
ADD: .. and other header files as well.
-
Yea, you need to use rb_str_new2 to convert the Cstring to a Ruby String.
-
Thanks Dan
-
Dan, what is the Block expected in
rb_funcall(menu, rb_intern('add_submenu')...
I keep getting the error "tried to create Proc object without a block" if I use 1 arg.
If I use 2 arg, I get "wrong number of arguments (2 for 1)" but even you said it needs 2!? Confusing
-
@alienizer said:
For the Block, do I have to use rb_something to pass the Block, or just the reference pointer?
Not sure... the proc and block functions are listed in intern.h
Depends on if the block / proc will be defined at runtime on the Ruby side, or before hand in your C code.
This generated doxygen website is old (v 1.8.4) but you may find it easier to find things:
http://www.ruby-doc.org/doxygen/current/globals.html#index_r -
Thanks Dan
-
@alienizer said:
Thanks Dan
no problemo ...
Also, if you have the Ruby Reference CHM, when you wish to see the C-side source for a method, you can click within the method's definition area, and a source box will unfold.
-
Sweet! But only ruby18-core.chm works out of the 3! Or is it me?
I just posted http://forums.sketchucation.com/viewtopic.php?f=180&t=39119 another challange for you
-
@alienizer said:
Sweet! But only ruby18-core.chm works out of the 3! Or is it me?
ruby18.chm is a wrapper that loads both of the other two, as expandable nodes in the tree control.
CHM files use a MSIE stub named hh.exe
They a compiled HTML Help Markup files.
You can get the HTML Help Workshop app on MS Download. -
Yes indeed, I didn't know the other 2 were loaded into the one. That's a nice ref book! Thanks Dan.
-
@alienizer said:
Yes indeed, I didn't know the other 2 were loaded into the one. That's a nice ref book! Thanks Dan.
Well it's supplied with the mingGW compiled Windows Ruby one-click install packages. So I'm not responsible.
Check your Private Messages
-
@dan rathbun said:
Well it's supplied with the mingGW compiled Windows Ruby one-click install packages. So I'm not responsible.
I know, but I should have figured it out myself
-
why would you use
Sketchup.send_action(JcB::My_Ext.initalise)
when
JcB::My_Ext.initalise
works for a loaded file?
john
-
looks like you solved the problem.
If I want to call an rb function, from a loaded rb in SU, you could just send this function from a dll:
Sketchup.send_action my_rb_function_def_name_in_an_rb_loaded_file (no string wrap), as you can other SU commands
which rb SU command, and its function call string is just a string in a class property or in some dll function, thus called in either direction, from dll, or to dll.
Its a little clunky I notice, a bit unreliable after the stack is toasted a little.
Advertisement