News for hackers. Stuff that matters.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Saturday November 09, 2019 @03:48PM (#21494251)
> 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.

Re:Show HN: LuaJIT assembler/assembly language for direct by... by rafa1981 on Saturday November 09, 2019 @04:39PM (#21494560)
I don't know if luajit runs in your device, but vanilla luajit supports generating and loading bytecode.

https://luajit.org/running.html

Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Saturday November 09, 2019 @05:49PM (#21495031)
I 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.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by rafa1981 on Monday November 11, 2019 @07:23AM (#21504227)
Notice 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.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by Rochus on Sunday November 10, 2019 @05:49AM (#21497456)
I don't think this work fits your needs. Have a look at something like https://en.wikipedia.org/wiki/NodeMCU or http://www.eluaproject.net/ or https://github.com/whitecatboard/Lua-RTOS-ESP32 instead.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Sunday November 10, 2019 @04:42PM (#21500356)
The 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.

Re:Show HN: LuaJIT assembler/assembly language for direct by... by connicpu on Saturday November 09, 2019 @06:03PM (#21495097)
The 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
Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Saturday November 09, 2019 @09:18PM (#21495992)
Any examples of code or know where someone has done this?
Re:Show HN: LuaJIT assembler/assembly language for direct by... by matheusmoreira on Saturday November 09, 2019 @11:13PM (#21496361)
Lua was made for this! Here's a simple example:

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

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_load

Re:Show HN: LuaJIT assembler/assembly language for direct by... by bryanrasmussen on Saturday November 09, 2019 @04:11PM (#21494378)
Normally JavaScript is a JIT compiled language because of the need to do stuff like hoisting etc.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by Stratoscope on Saturday November 09, 2019 @05:50PM (#21495040)
Just 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.

Re:Show HN: LuaJIT assembler/assembly language for direct by... by bryanrasmussen on Sunday November 10, 2019 @03:21AM (#21497072)
yeah but I was just nitpicking on the "interpreted" statement above. What comes around goes around I guess.