Simple Extension for Mac
-
@thomthom said:
Thanks, ThomThom, that looks like what I am looking for.
I see you had posted it before, but I didn't know what it was at the time.
-
Mind you, I recently found http://rubyinstaller.org/downloads/ which I think is a better choice for Windows than the Visual Studio solution I'd used.
-
I've been playing around with C Extension recently and I would like to know how if there is an equivalent of is_a? ruby function in C level.
I found rb_obj_is_instance_of but it seems to be only meant for native ruby types.
-
[Ignore this for a minute - I need to add a second parameter for what the value to pass to is_a?]
You can execute the equivalent of any ruby function using rb_intern() and rb_funcall()
Try this:
VALUE fid = rb_intern("is_a?"); VALUE vret = rb_funcall(klass, fid, 0);
-
Here is a better example, equivalent to
Sketchup.is_a?(Module)
VALUE Sketchup = rb_path2class("Sketchup"); VALUE Module= rb_intern("Module"); VALUE is_a = rb_intern("is_a?"); VALUE result = rb_funcall(Sketchup, is_a, Module, 0);
-
@olilej said:
I've been playing around with C Extension recently and I would like to know how if there is an equivalent of is_a? ruby function in C level.
If you have the CHM... you can click on the method description, and the C source will popup:
(Also works for online version, but the source link must be clicked directly, and is only visible when the mouse is hovering over the method description.) -
So it looks like there are some macros defined in C, to make life easier ... CLASS_OF(), RCLASS_SUPER(), etc.
-
-
Great, my goal is to make sure I'm dealing with a Entity in order to access its attributes.
Here is the code I've come up with.
VALUE result = rb_obj_is_kind_of(obj, rb_path2class("Sketchup;;Entity")); if (Qtrue == result){ VALUE rval = rb_funcall(obj, rb_intern("get_attribute"), 2, rb_str_new2("dynamic_attributes"), rb_str_new2("...")); ... }
-
Only
Sketchup::ComponentDefinition
andSketchup::ComponentInstance
will have dictionaries with that special name.
Advertisement