lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



I have a small question. In my project I will do some modifications
to the Lua 5.2 interpreter to implement some things more efficient
for our purposes.
As most changes are in the lvm.c luaV_execute function I wanted to
have a full coverage unit test of that function. Unfortunately I
haven't managed to provoke a OP_LOADKX. Maybe someone has an idea,
or even better sample lua code that will compile and run a OP_LOADKX
operation?
local a = {"return {0"}
for i = 1,2^18 + 10 do
   a[#a + 1] = i
end
a[#a + 1] = "}"
local f = assert(loadstring(table.concat(a, ",")))

Function 'f' should have 11 occurences of 'OP_LOADKX'.

-- Roberto


Thank you very much, the code works well. The OP_LOADKX case in lvm.c is executed 11 times. I replaced "loadstring" by "load" I don't have any compatibility defines active ;)

I added this two lines to the code:
local b = f()
return b[#b]

Then I can check the last element of the table by the result of my test code. I suppose that OP_LOADKX was involved in loading the last element.

-- Thomas