Example #1
0
 static Lua.Proto combine(Lua.LuaState L, int n)
 {
     if (n == 1)
     {
         return(toproto(L, -1));
     }
     else
     {
         int       i, pc;
         Lua.Proto f = Lua.luaF_newproto(L);
         Lua.setptvalue2s(L, L.top, f); Lua.incr_top(L);
         f.source       = Lua.luaS_newliteral(L, "=(" + PROGNAME + ")");
         f.maxstacksize = 1;
         pc             = 2 * n + 1;
         f.code         = (Instruction[])Lua.luaM_newvector <Instruction>(L, pc);
         f.sizecode     = pc;
         f.p            = Lua.luaM_newvector <Lua.Proto>(L, n);
         f.sizep        = n;
         pc             = 0;
         for (i = 0; i < n; i++)
         {
             f.p[i]       = toproto(L, i - n - 1);
             f.code[pc++] = (uint)Lua.CREATE_ABx(Lua.OpCode.OP_CLOSURE, 0, i);
             f.code[pc++] = (uint)Lua.CREATE_ABC(Lua.OpCode.OP_CALL, 0, 1, 1);
         }
         f.code[pc++] = (uint)Lua.CREATE_ABC(Lua.OpCode.OP_RETURN, 0, 1, 0);
         return(f);
     }
 }