inline functions

37 views
Skip to first unread message

Ricardo Quesada

unread,
May 14, 2012, 8:54:12 PM5/14/12
to jsc...@googlegroups.com
Hi,

I am playing with the most recent version of JSCocoa.
And I noticed that I can't use custom inline C function (previously loading the BridgeSupport file), but for example, CGPointMake works OK.

Any idea ? 

Thanks.

Patrick Geiller

unread,
May 14, 2012, 9:42:26 PM5/14/12
to jsc...@googlegroups.com
I am playing with the most recent version of JSCocoa.
And I noticed that I can't use custom inline C function (previously loading the BridgeSupport file), but for example, CGPointMake works OK.

Inline functions are compiled every time they're used, so they don't exist as something that can be called.

BridgeSupport can handle inline functions like CGPointMake because they're defined in an external library. 
(CoreGraphics.framework/Versions/A/Resources/BridgeSupport/CoreGraphics.dylib)

See the help of gen_bridge_metadata

     Certain elements, such as inline functions, cannot be described in the metadata files. It is therefore
     required to generate a dynamic library in order to make the bridges use them. The gen_bridge_metadata
     tool can take care of that for you.

Ricardo Quesada

unread,
May 15, 2012, 12:24:59 AM5/15/12
to jsc...@googlegroups.com
Thanks. It makes sense.

Ricardo Quesada

unread,
May 15, 2012, 7:58:25 PM5/15/12
to jsc...@googlegroups.com
So, I created a dylib with gen_bridge_metada -F dylib, and now all the inline functions are in the dylib (I verified this with the 'nm' command line tool).

My question is: how can I use this dylib inside my project ?
I added it in the "copy resources", also in the "link binary with libraries", but when I load the app it fails with this error:

dyld: Library not loaded: ../Resources-Mac/cocos2d-mac.dylib

Reason: image not found


Should I call dyld manually ?

Do you know where should I put the .dylib file ? If possible, I would like to avoid changing the LD_LIBRARY_PATH environment.


Thank you,


Ricardo

Ricardo Quesada

unread,
May 15, 2012, 8:43:16 PM5/15/12
to jsc...@googlegroups.com
Ignore my previous question (I managed to load the .dylib).

My current problem is that when I call the inline function from javascript, JSCocoa gives me this error:

2012-05-15 17:34:53.908 JavascriptTest[24154:503] toJSValueRef FAILED

2012-05-15 17:34:53.908 JavascriptTest[24154:503] JSException: Return value not converted in ccc4f on line 369 of /Users/rquesada/Library/Developer/Xcode/DerivedData/cocos2d-mac-elbpvrbdkhijembzvwboldykqqaq/Build/Products/Debug/JavascriptTest.app/Contents/Resources/js/test-action.js


ccc4 is defined like this:

struct ccColor4F {

GLfloat r;

GLfloat g;

GLfloat b;

GLfloat a;

};

typedef struct ccColor4F ccColor4F;


static inline ccColor4F ccc4f(const GLfloat r, const GLfloat g, const GLfloat b, const GLfloat a)

{

return (ccColor4F){r, g, b, a};

}


And the BridgeSupport for ccColor4F is:

<struct name='ccColor4F' type='{ccColor4F=&quot;r&quot;f&quot;g&quot;f&quot;b&quot;f&quot;a&quot;f}'>

<field name='r' declared_type='GLfloat' type='f'/>

<field name='g' declared_type='GLfloat' type='f'/>

<field name='b' declared_type='GLfloat' type='f'/>

<field name='a' declared_type='GLfloat' type='f'/>

</struct>



I am using the most recent JSCocoa from github, and I am manually loading the bridgesupport file with:

[[BridgeSupportController sharedController] loadBridgeSupport:cocos2dBridgeFilePath];




Am I doing something wrong ? Am I missing something ?

Thank you,

Ricardo

Patrick Geiller

unread,
May 16, 2012, 12:42:25 PM5/16/12
to jsc...@googlegroups.com

2012-05-15 17:34:53.908 JavascriptTest[24154:503] toJSValueRef FAILED

2012-05-15 17:34:53.908 JavascriptTest[24154:503] JSException: Return value not converted in ccc4f on line 369 of /Users/rquesada/Library/Developer/Xcode/DerivedData/cocos2d-mac-elbpvrbdkhijembzvwboldykqqaq/Build/Products/Debug/JavascriptTest.app/Contents/Resources/js/test-action.js



Fixed, please pull.

Ricardo Quesada

unread,
May 16, 2012, 2:02:32 PM5/16/12
to jsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages