4 ms·
Developing a Lua VM in JavaScript
- jrogers65 14y agoLayer 1 - assembly to get the system to boot and communicate with hardware. Layer 2 - C to schedule tasks, manage memory, provide filesystem support. Layer 3 - C/C++ to provide a graphical user interface framework. Layer 4 - C/C++ to render web pages. Layer 6 - C/C++ to implement a Javascript VM. Layer 7 - Javascript to implement a Lua interpreter. Layer 8 - Game engine written in Lua. Layer 9 - Game specific code written in Lua. I wonder how much bang per Mhz this setup provides.
- azakai 14y agoThese layers aren't literal, though. For example, the JS VM can generate native machine code that can run just as fast as the assembly in layer 1. It's literally in the same language. (It won't be as fast always, of course, but in some cases it will.) Also, there is no reason Lua in JS could not run at similar speed to JS, if the translation from Lua to JS is efficient enough. Whether that is possible depends on how close Lua and JS semantics are. That could also be at least partially achieved by using a Lua VM that has a JIT, and implementing a JIT backend that emits JS. Such an approach could be quite fast.
- otibom 14y agoThere's always emscriptem https://github.com/kripken/emscripten https://github.com/kripken/emscripten
- jws 14y agoI'm down the same road. For me the amount of time in Lua is negligible. Rendering is the long pole which is mostly off in the graphics card.
- EastLondonCoder 14y agoDisclaimer, I work on the project. Not so much the vm as the game engine part. The game engine is a Lua api but implemented in the host language. In this case js but we have a obj-c iOS implementation as well. For our use case the bottleneck is not the Lua interpreter but graphics rendering. The system is currently live and you can see it working if you go to www.jackpotjoy.com with an iPad user agent. If you have any specific questions I'd be happy to answer them.
- cmwelsh 14y agoI would be interested to see the author's thoughts on Lua.js, translating Lua into semi-equivalent JavaScript: https://github.com/mherkender/lua.js https://github.com/mherkender/lua.js Or is this more of an educational than practical workshop?
- corysama 14y agoSimilar project that converts specifically the LuaJIT bytecode to JS https://github.com/creationix/brozula https://github.com/creationix/brozula