[MacRuby-devel] Exposing c structs and functions
Jim Getzen
jim at getzen.name
Fri Dec 19 12:03:30 PST 2008
OK, I decided to devote a little time to see if I could make any
headway with BridgeSupport. It doesn't seem too terribly complicated,
but I have run into a problem.
My framework is called ZenGL, so I first created a struct in ZenGL.h
based on NSPoint:
typedef struct _ZPoint {
float x;
float y;
} ZPoint;
I also created a ZPointMake function:
ZPoint ZPointMake(float x, float y);
Then, I rebuilt the framework. Fine so far.
Next, I created an XML ZenGL.bridgesupport file using Foundation.xml
(in /Library/BridgeSupport/) as an example. Here are the contents:
<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd
">
<signatures version='0.9'>
<struct name='ZPoint'
encoding='{_ZPoint="x"f"y"f}'
type='{_ZPoint="x"f"y"f}'/>
<function name='ZPointMake'>
<function_arg type='f'/>
<function_arg type='f'/>
<function_retval type='{_ZPoint="x"f"y"f}'/>
</function>
</signatures>
I placed ZenGL.bridgesupport in the folder with my built MacRuby app
and added this code to load it:
load_bridge_support_file './ZenGL.bridgesupport'
(Going back to my xml, I originally did not include a 'type' attribute
for the struct since the NSPoint example in Foundation.xml did not
have one, but I received an error when running the load_... command.
Not sure why.)
All seems well, but when I try this code from MacRuby:
zp = ZPointMake(10.0, 10.0)
I get this error:
`ZPointMake': wrong number of arguments (2 for 0) (ArgumentError)
My ZPointMake function definition in the xml sure looks right to me,
based on the examples in Foundation.xml, so what have I done wrong?
Jim
More information about the MacRuby-devel
mailing list