• SpiderMonkey embedding in

    From Nightfox@DIGDIST/BATTLEST/FREEWAY to All on Tue Oct 1 21:28:00 2013
    Recently at work, I've started using Mozilla's SpiderMonkey JavaScript engine in one of our C++ apps to allow the application to run scripts made with JavaScript. It seems to make more sense than trying to make our own scripting language - With a JavaScript engine, all we need to do is define functions we want to be able to call from the scripting language, and since JavaScript is an existing language, we can leverage its mechanism to use variables, looping, string manipulation, and other built-in functions that JavaScript provides.

    We have made other scriptable applications using primitive scripting languages that we've created, but I think using a mature, existing scripting language provides a lot more flexibility.

    Mozilla's SpiderMonkey documentation seems to be slightly out of date, so I had to modify Mozilla's sample Hello World code a bit to get it to compile and run, but I eventually got there. I think it's pretty cool to be able to have a compiled app be able to load and execute code from a scripted language.

    Mozilla SpiderMonkey 17 (implementing SpiderMonkey 1.8.5) is available for download here:
    https://developer.mozilla.org/en-US/docs/SpiderMonkey/17

    Guide to embedding SpiderMonkey (with some example Hello World code): https://developer.mozilla.org/en-US/docs/How_to_embed_the_JavaScript_engine

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com