On 18-Jan-07, at 6:53 PM, Chris wrote:
> What happened to the arguments in the first case?
They got lost because ... is not a variable.
When you compile multiple files, luac assembles them as though
you'd written:
(function(...)
<file1>
end)()
(function(...)
<file2>
end)()
return (function(...)
<filen>
end)()
(except there are no line ends so the line numbers are preserved.)
What you (probably) want is the following conversion:
(function(...)<file1> end)(...)
(function(...)<file2> end)(...)
return (function(...)<filen> end)(...)
Since that's not very pretty to do in Lua (it's hard to retain the
correct line numbers while doing the combination), you could try the
following patch to luac.c:
--- ../../lua-5.1.1/src/luac.c Fri Jun 2 12:37:11 2006
+++ luac.c Thu Jan 18 21:01:30 2007
@@ -126,8 +126,9 @@
Proto* f=luaF_newproto(L);
setptvalue2s(L,L->top,f); incr_top(L);
f->source=luaS_newliteral(L,"=(" PROGNAME ")");
- f->maxstacksize=1;
- pc=2*n+1;
+ f->maxstacksize=2;
+ f->is_vararg = VARARG_ISVARARG;
+ pc=3*n+1;
f->code=luaM_newvector(L,pc,Instruction);
f->sizecode=pc;
f->p=luaM_newvector(L,n,Proto*);
@@ -137,7 +138,8 @@
{
f->p[i]=toproto(L,i-n-1);
f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i);
- f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1);
+ f->code[pc++]=CREATE_ABC(OP_VARARG,1,0,0);
+ f->code[pc++]=CREATE_ABC(OP_CALL,0,0,1);
}
f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0);
return f;