Exemplo n.º 1
0
        public int L_Ref(int t)
        {
            if (API.IsNil(-1))
            {
                API.Pop(1);                      // remove from stack
                return(LuaConstants.LUA_REFNIL); // `nil' has a unique fixed reference
            }

            t = API.AbsIndex(t);
            API.RawGetI(t, FreeList);          // get first free element
            int reference = API.ToInteger(-1); // ref = t[freelist]

            API.Pop(1);                        // remove it from stack
            if (reference != 0)                // any free element?
            {
                API.RawGetI(t, reference);     // remove it from list
                API.RawSetI(t, FreeList);      // t[freelist] = t[ref]
            }
            else                               // no free elements
            {
                reference = API.RawLen(t) + 1; // get a new reference
            }
            API.RawSetI(t, reference);
            return(reference);
        }
Exemplo n.º 2
0
 public void L_Unref(int t, int reference)
 {
     if (reference >= 0)
     {
         t = API.AbsIndex(t);
         API.RawGetI(t, FreeList);
         API.RawSetI(t, reference);                // t[ref] = t[freelist]
         API.PushInteger(reference);
         API.RawSetI(t, FreeList);                 // t[freelist] = ref
     }
 }
Exemplo n.º 3
0
        public bool L_CallMeta(int obj, string name)
        {
            obj = API.AbsIndex(obj);
            if (!L_GetMetaField(obj, name))                // no metafield?
            {
                return(false);
            }

            API.PushValue(obj);
            API.Call(1, 1);
            return(true);
        }
Exemplo n.º 4
0
 public int L_GetSubTable(int index, string fname)
 {
     API.GetField(index, fname);
     if (API.IsTable(-1))
     {
         return(1);
     }
     else
     {
         API.Pop(1);
         index = API.AbsIndex(index);
         API.NewTable();
         API.PushValue(-1);
         API.SetField(index, fname);
         return(0);
     }
 }