I am writing Lua code that can read the bytecode generated by the string.dump () function. I assume (since it allows several optimizations and less coding) that all OP_JMP instructions increment the instruction pointer forward when used for if statements. They could technically jump back because they use the sBx value (which may be negative). I'm only interested in the bytecode of the if statements from the standard Lua 5.1 implementation.
I used chunkspy (awesome btw tool) to look at the bytecode for several samples.
Here is the basic if statement:
a, b = 1, 2 if a == b then print '=' elseif a < b then print '<' else print '>' end
He makes four jumps, none of which are negative:
[08] jmp 4; to [13] [12] jmp 11; to [24] [16] jmp 4; to [21] [20] jmp 3; to [24]
I tried to find the answers in the Lua source code , but it just turned out to be confusing (I'm sure this is super elegant code if I took the time to handle this).
Does anyone know of a case for if statements, where the lua OP_JMP statement has a negative value for sBx, or knows if they are always positive values?
source share