示例#1
0
 public Closure()
 {
     c = new CClosure(this);
       l = new LClosure(this);
 }
示例#2
0
文件: lvm.cs 项目: chenzuo/SharpLua
        static int gettablescope(LuaState L, TValue ra, TValue rb,
                   InstructionPtr pc, LClosure cl, StkId pbase)
        {
            /* Look for closest containing "o {....}" where o
               has a __scope metamethod. */
            StkId base_ = pbase;
            InstructionPtr pi;
            TValue tm = null;
            int previousIndex = pc.pc;
            for (pi = new InstructionPtr(pc.codes, pc.pc); ; pi.pc++)
            {
                /* Search forward for end of any "o {....}".
                   Note: "o {....}" is terminated by
                     (NEWTABLE,CALL) for empty table
                     (SETLIST,CALL)  for table with array part or "..."
                     (SETTABLE,CALL) for table with hash part only
                 */
                if (pi.pc >= /*cl.p.code + */cl.p.sizecode)// || pi.pc >= pi.codes.Length)
                    break;
                if (GET_OPCODE(pi.codes[pi.pc]) == OpCode.OP_CALL &&
                    (GET_OPCODE(pi.codes[pi.pc - 1]) == OpCode.OP_SETLIST ||
                     GET_OPCODE(pi.codes[pi.pc - 1]) == OpCode.OP_SETTABLE))
                {
                    /* Determine whether this "o {....}" contains the GETGLOBAL by
                       searching for start of this "o {....}", which is implied
                       by condition RA(NEWTABLE) == RA(SETLIST or SETTABLE).
                     */
                    InstructionPtr pi2;
                    bool is_containing = false;
                    for (pi2 = new InstructionPtr(pi.codes, pi.pc); ; pi2.pc--)
                    {
                        lua_assert(pi2.pc >= /*cl.p.code*/cl.p.sizecode);
                        if (GET_OPCODE(pi2.codes[pi2.pc]) == OpCode.OP_NEWTABLE &&
                            RA(L, base_, pi2.codes[pi2.pc]) == RA(L, base_, pi.codes[pi.pc - 1]))
                        {
                            is_containing = (pi2 < pc);
                            break;
                        }
                    }
                    /* Search complete if o has __scope metamethod (tm). */
                    if (is_containing &&
                        !ttisnil(tm = luaT_gettmbyobj(L, RA(L, base_, pi.codes[pi.pc]), TMS.TM_SCOPE)))
                    {
                        break;
                    }
                }
                //Console.WriteLine(pi.pc);
            } /* pi */

            pc.pc = previousIndex;
            /* Lookup key first in __scope (if available). Found if non-nil. */
            if (tm != null && !ttisnil(tm))
            {
                luaV_gettable(L, tm, rb, ra);
                if (!ttisnil(ra))
                {
                    //Console.WriteLine("Found __scope object!");
                    return 1;
                }
            }
            return 0;
        }