8

I would like to embed a javascript engine into an ANSI C application.

In fact, I would like to be able to run some code entered on runtime, while being able to interact with some C variables and functions.

So, is V8 the only choice? Where should I start?

osgx
  • 90,338
  • 53
  • 357
  • 513
Stasik
  • 2,568
  • 1
  • 25
  • 44
  • 2
    Why not something like Lua? There are several javascript engines, V8 is one of fastest, but not very portable. Other choices for JS: http://en.wikipedia.org/wiki/JavaScript_engine#JavaScript_engines If you want to interact with C, there is [Cint](http://en.wikipedia.org/wiki/Cint) - C language embeddable interpreter. – osgx Jun 30 '12 at 11:34
  • Would you point me to LUA homepage (even with LMGIFY). Any experiences with spidermonkey? – Stasik Jun 30 '12 at 11:45
  • "Lua homepage" -> first result (in google.com/ncr) "The Programming Language Lua http://www.lua.org/" (or use en.wikipedia.org). I think, huge (fast) JS engines are not so easy to integrate. I have not experience with this JS, but [this page](https://developer.mozilla.org/en/How_to_embed_the_JavaScript_engine) says that embedding of SpiderMonkey is easy. – osgx Jun 30 '12 at 11:49
  • yep, i was exactly at this page. Will try to compile it in in the evening. Wonder if c99 embedding will work. Thanks, osgx, you on habr? – Stasik Jun 30 '12 at 11:57

1 Answers1

4

There are some "embedding quickstart" pages:

V8 JS Engine (WebKit):

https://developers.google.com/v8/get_started

https://developers.google.com/v8/embed

SpiderMonkey JS Engine (Firefox):

https://developer.mozilla.org/en/How_to_embed_the_JavaScript_engine

LUA: http://heavycoder.com/tutorials/lua_embed.php http://www.ibm.com/developerworks/linux/library/l-embed-lua/

After quick looking into these links I think that V8 is more complex; both Lua and SM are easy to integrate into application. And to call C functions from SM or Lua you should write some wrapper code for every function.

osgx
  • 90,338
  • 53
  • 357
  • 513
  • Can you be more specific on what type of wrapper code we should be writing? – triple Jun 12 '13 at 01:50
  • triple, start from https://developers.google.com/v8/get_started page. Wrapper is only needed if you want to call native (C) functions from JS code. – osgx Jun 12 '13 at 08:01