4 ms·
> LuaJIT as a backend for another language, not primarily Lua programmers Not exactly backend but that kinda fits my use case. I have a C embedded application
by SlowRobotAhead 7y ago
> LuaJIT as a backend for another language, not primarily Lua programmers
Not exactly backend but that kinda fits my use case. I have a C embedded application that I need scripting on. Nothing unsecure from the user, from my own backend, but it requires a foreign function interface, and its a super constrained device.
Lua, JavaScript, forth, etc. None I’ve been able to find anything I like under 50 kB flash or are even slightly “friendly”.
Found one in JavaScript was close, but it’s an interpreted language which means every letter of code is a byte I need to transfer then have parsed.
I’ll look into this. Esp if it’s still possible to send just bytecode in.
- bryanrasmussen 7y agoNormally JavaScript is a JIT compiled language because of the need to do stuff like hoisting etc.
- Stratoscope 7y agoJust a nit on the JIT... JavaScript is almost always compiled, regardless of whether there is a JIT or not. A typical JavaScript system first compiles the JS source code into bytecode. Then it starts executing (interpreting) the bytecode. If there is a JIT, that is a second compiler. It monitors the execution of the bytecode to find hot spots where it compiles the bytecode into machine language.
- bryanrasmussen 7y agoyeah but I was just nitpicking on the "interpreted" statement above. What comes around goes around I guess.
- rafa1981 7y agoI don't know if luajit runs in your device, but vanilla luajit supports generating and loading bytecode. https://luajit.org/running.html https://luajit.org/running.html
- SlowRobotAhead 7y agoI think primarily it’s the ffi I would be missing. This would get me a turing complete language but set up as an executable it’s wrong for me.
- rafa1981 7y agoNotice that if I remember correctly, you can generate bytecode on the PC (by using the luajit command) and have the resulting bytecode loaded through the C API on your device as if it were a regular script.
- connicpu 7y agoThe basic lua VM (not luajit) is only like 11kb compiled. You can't directly do FFI from lua, but you can set up the FFI functions from the C API
- SlowRobotAhead 7y agoAny examples of code or know where someone has done this?
- matheusmoreira 7y agoLua was made for this! Here's a simple example: https://gist.github.com/Vesnica/3672425 https://gist.github.com/Vesnica/3672425 It loads and runs a Lua source code file which calls the exported C function. Lua compiles the source code into byte code before running it but that can also be done ahead of time with the Lua compiler: https://www.lua.org/manual/5.3/luac.html https://www.lua.org/manual/5.3/luac.html It can also be done manually with the dump and load functions: https://www.lua.org/manual/5.3/manual.html#lua_dump https://www.lua.org/manual/5.3/manual.html#lua_dump https://www.lua.org/manual/5.3/manual.html#lua_load https://www.lua.org/manual/5.3/manual.html#lua_load
- Rochus 7y agoI don't think this work fits your needs. Have a look at something like https://en.wikipedia.org/wiki/NodeMCU https://en.wikipedia.org/wiki/NodeMCU or http://www.eluaproject.net/ http://www.eluaproject.net/ or https://github.com/whitecatboard/Lua-RTOS-ESP32 https://github.com/whitecatboard/Lua-RTOS-ESP32 instead.
- SlowRobotAhead 7y agoThe problem with eLua and others is that they either try and replace C or they focus on the headers/registers/peripherals of the micro. Design it to be the environment you do all your work in. Get there, stay there. It’s why eLua appears to have terrible micro support because they only have the bandwidth for specific chips. Other options like MicroPython have a VM you are never supposed to leave. I think you’re right that Lua is the way to go. But I have yet to see someone package it nicely for gcc and to be included and built from an MCU IDE (Keil, Segger Emebbeded, IAR, etc). I’ll keep looking.