In Python you have the ability to view the compiled bytecode of a user-defined function using dis
.
Is there a builtin equivalent to this for Lua?
It would really useful!
In Python you have the ability to view the compiled bytecode of a user-defined function using dis
.
Is there a builtin equivalent to this for Lua?
It would really useful!
Chunkspy might be what you're looking for. Quoting from the site:
ChunkSpy is a tool to disassemble a Lua 5 binary chunk into a verbose listing that can then be studied. Its output bears a resemblance to the output listing of assemblers. I wanted something that can tell me in great detail what goes on inside a Lua binary chunk file, not just the instructions. It is intended to be a tool for learning Lua internals as well.
The luac
utility that comes with standard lua can create an assembly listing from Lua source using its -l
option. For example, compiling from source on stdin
:
C:...> echo a=b | luac -l - main (3 instructions, 12 bytes at 00334C30) 0+ params, 2 slots, 0 upvalues, 0 locals, 2 constants, 0 functions 1 [1] GETGLOBAL 0 -2 ; b 2 [1] SETGLOBAL 0 -1 ; a 3 [1] RETURN 0 1 C:...>
You can also use luac -l
to compile a lua file and output the disassembly.