4 ms·
seems the C interface is modelled after Lua. Is there any inspiration there?
by mempko 12y ago
seems the C interface is modelled after Lua. Is there any inspiration there?
- macournoyer 12y agoPretty sure. The instruction layout is also inspired by Lua: https://github.com/svaarala/duktape/blob/master/src/duk_js_bytecode.h#L8-L30 https://github.com/svaarala/duktape/blob/master/src/duk_js_b... Here's Lua: https://github.com/lua/lua/blob/master/src/lopcodes.h#L13-L29 https://github.com/lua/lua/blob/master/src/lopcodes.h#L13-L2...
- weeksie 12y agoI immediately thought of Lua as well. A fine choice, Lua has the best C FFI I've ever worked with. I love everything about this.
- cheez 12y agoDoes Lua work well with multiple threads?
- haberman 12y agoLua has full support for creating multiple interpreter instances (ie. there are no global variables, and it's totally re-entrant). But interpreter instances are not thread-safe. So the way to support multiple threads is to have completely independent interpreters running in different threads.
- cheez 12y agoThanks. Any idea as to the footprint of these instances?
- mempko 12y agoI use this approach in Fire★ (http://www.firestr.com http://www.firestr.com). Lua vm instances are tiny. There is a reason lua is used even in systems like nintendo DS
- sharkbot 12y agoYou can make a Lua interpreter thread safe by adding a GIL. There is implicit support for this in the code: the interpreter invokes lua_lock/lua_unlock at the proper places, the default Lua implementation just has them NOP'd out. Adding the thread primitives is up to you, however.
- chii 12y agowhen you have multiple threads, isn't the idea to share data between threads? I haven't really worked with embedded lua before - does lua help with that?
- bodyfour 12y agoYes, very much so. If you've embedded lua before it's very easy to do the same with duktape. A few conventions are different -- for instance stack indicies are 0-based instead of 1-based (mirroring the difference in JS vs Lua) and some of the strategies for interfacing with native-code objects is different (JS prototypes aren't exact analogues to Lua metatables, etc)
- svaarala 12y agoAbsolutely, the original motivation was to have a Lua-like implementation for Javascript.
- creationix 12y agoAnd thank you! I've wanted this for years, but haven't yet gotten up the courage to actually tackle it. ES5.1 is big and ES6 is massive.
- Aldo_MX 12y agoI really want to applaud your effort. Are you accepting donations?
- svaarala 12y agoThanks! At the moment no, but send me an e-mail if you use Duktape somewhere :)