lua-users home
lua-l archive

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


I would guess that LuaJIT does not run with compatibility mode on.
That way of handling varargs was deprecated in 5.1, but is enabled in
standard lua as a compatibility option. See here for a listing of
changes, and the corresponding compatibility flags:
http://www.lua.org/manual/5.1/manual.html#7

On Jan 3, 2008 10:27 AM, Cheng, Long <long.x.cheng@gmail.com> wrote:
> Hi all:
> Today I tried to embed luajit project into our project (for better lua
> performance of course), and found that luajit can not correctly compile
> and run vararg functions. In perticular, the following lua code will
> fail to execute on luajit:
>
> --- begin of test.lua
> function test(...)
> for i=1, #arg do
> print(arg[i])
> end
> end
>
> test(1,2,3)
> --- end of test.lua
>
> on luajit, this code will produce the following error message:
>
> luajitexe: stdin:4: attempt to get length of global 'arg' (a nil value)
> stack traceback:
> stdin:4: in function 'test'
> stdin:9: in main chunk
> [C]: ?
>
> The following debug dumps also shows that luajit does not correctly
> handle the vararg function:
> Here is the dump from stock lua 5.1.2 vm (luac -l test.lua)
>
> function <test.lua:3,7> (9 instructions, 36 bytes at 00421630)
> 0+ params, 7 slots, 0 upvalues, 5 locals, 2 constants, 0 functions
> 1 [4] LOADK 1 -1 ; 1
> 2 [4] LEN 2 0
> 3 [4] LOADK 3 -1 ; 1
> 4 [4] FORPREP 1 3 ; to 8
> 5 [5] GETGLOBAL 5 -2 ; print
> 6 [5] GETTABLE 6 0 4
> 7 [5] CALL 5 2 1
> 8 [4] FORLOOP 1 -4 ; to 5
> 9 [7] RETURN 0 1
>
> and here is the dump from luajit 1.1.3 (luajit -j dumphints < test.lua)
> #NOCLOSE
> 0001 LOADK 0 -1 ; 1
> 0002 GETGLOBAL 1 -2 ; "arg"
> 0003 LEN 1 1
> 0004 LOADK 2 -1 ; 1
> 0005 FORPREP 0 => 0010 #FOR_STEP_K #TYPE(integer)
> 0006 => GETGLOBAL 4 -3 ; "print"
> 0007 GETGLOBAL 5 -2 ; "arg"
> 0008 GETTABLE 5 5 3 #TYPEKEY(integer)
> 0009 CALL 4 2 1 #TYPE(C)
> 0010 FORLOOP 0 => 0006
> 0011 RETURN 0 1
>
> We can see that here luajit generated code tries to read the global
> variable "arg" which does not exist.
>
> I haven't try to look at luajit source code for the problem yet. I'm
> asking on this mailist hoping that someone can help me on the following
> questions:
> 1. Is there anything wrong on my setup? Or it is a known problem of
> luajit to not handling vararg functions.
> 2. If it is a known problem of luajit, does the developers already have
> plan to fix it? If not, I'd like to contribute some efforts to fix this
> problem.
>
> Thanks!
>
> Regards
> Long
>