Embedding Google V8 into ANSI C Application - where to start?
Asked Answered
H

1

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?

Hawthorne answered 30/6, 2012 at 10:59 Comment(4)
Why not something like Lua? There are several javascript engines, V8 is one of fastest, but not very portable. Other choices for JS: en.wikipedia.org/wiki/JavaScript_engine#JavaScript_engines If you want to interact with C, there is Cint - C language embeddable interpreter.Jon
Would you point me to LUA homepage (even with LMGIFY). Any experiences with spidermonkey?Hawthorne
"Lua homepage" -> first result (in google.com/ncr) "The Programming Language Lua 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 says that embedding of SpiderMonkey is easy.Jon
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?Hawthorne
J
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.

Jon answered 30/6, 2012 at 11:51 Comment(2)
Can you be more specific on what type of wrapper code we should be writing?Emyle
triple, start from developers.google.com/v8/get_started page. Wrapper is only needed if you want to call native (C) functions from JS code.Jon

© 2022 - 2024 — McMap. All rights reserved.