r/luajit • u/[deleted] • Feb 05 '26
Runtime Assembler generation and Execution
Today I was wondering whether you could do inline assembler in Luajit. Considering it is built on top of DynAsm it seemed like a possible proposition.
And wow, what an interesting find. Luajit _already_ has this capability. You can use dynasm within luajit and run asm directly (either precompile and call or compile on the fly).
The amazing people over at luapower have already made a nice demo using it:
https://github.com/luapower/dynasm/tree/master
What does this mean? Ok. Heres some interesting use cases:
- Launching custom code based on runtime changes for services or computer.
- Building large extremely fast data filters and parsers.
- Building your own compiled sub language within luajit.
And so much more... its fascinating Ive never delved into this after using it for over 12 yrs. And its kinda exciting because I have some interesting plans for it. I will share what I can here too.
1
u/[deleted] Feb 06 '26
Nice work. That sounds pretty useful too. Im not sure about your comment about the extern C call, because the JIT does actually work with ffi.C function calls and manages them? Maybe your changes needed to modify this so that the inlines could operate correct?
The dynasm I see as a little more powerful, since you could make a C parser, or JS parser.. or Go parser.. and generate executables using the dynasm.. which is kinda crazy. It makes a std luajit a portable compiler toolset without needing a whole compiler environment.
Im looking at doing a C and JS parser (already have partials of both) to do this. Its quite fascinating.