Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

SpiderMonkey Question

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whelp, after spending the better part of the afternoon fighting with it, I've finally got SpiderMonkey integrated into my 4E4 game. I've got the Context creation and script execution all combined into a very attractive little class. I can call back into my C++ from javascript. The only problem is that I can't figure out how to call INTO the javascript from my C++ code. I've seen the tutorial that says, essentially: JS_CallFunctionName(cx, target, "onClick", 1, argv, &rval); However, I'm not trying to call a method to an object (the object being 'target' above), but rather a top-level function in the script... I've tried passing global ( JS_NewObject(cx, &global_class, NULL, NULL) ) as this parameter, but it doesn't work. Anyone got any experience in this area? ~Pax

Share this post

Link to post
Share on other sites
Whelp, I solved the problem. I guess I'm the only one here who uses SpiderMonkey ;p.

It's a pretty naste kludge, but it works:

BOOL ASpiderMonkeyScript::TriggerEvent(const char *event, const char *args)
char *buf;
BOOL ret;

buf = (char *)malloc(strlen(event) + strlen(args) + 6);
memset(buf, 0, strlen(event) + strlen(args) + 6);
sprintf(buf, "%s(%s)", event, args);

ret = ExecuteScript(buf);

return ret;

That done, I have to say I highly recommend SM. Once you get past the initialization and integration, it becomes really easy to work with.


Share this post

Link to post
Share on other sites
Aaaah a spidermonkey question, and I missed it... sob :(
You're not quite the only one using it.
As long as you have set the global object up in the standard way, ie:

rt = JS_NewRuntime(0x100000);
cx = JS_NewContext(rt, 0x1000);
JSClass global_class = {
global = JS_NewObject(cx, &global_class, NULL, NULL);
JS_InitStandardClasses(cx, global);
I think what you were originally trying to do should work. Interesting kludge though.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!