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); }
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 } }
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); }
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); } }