public object TopObjects(int from) { int top = LuaNativeMethods.lua_gettop(statePointer); int args = top - from; if (args == 0) { return(null); } else if (args == 1) { object o = LuaObject.CheckVar(statePointer, top); LuaNativeMethods.lua_pop(statePointer, 1); return(o); } else { object[] o = new object[args]; for (int n = 1; n <= args; n++) { o[n - 1] = LuaObject.CheckVar(statePointer, from + n); } LuaNativeMethods.lua_settop(statePointer, from); return(o); } }
public static int MakeArray(IntPtr ptr) { try { Type t; CheckType(ptr, 1, out t); LuaNativeMethods.luaL_checktype(ptr, 2, LuaTypes.TYPE_TABLE); int n = LuaNativeMethods.lua_rawlen(ptr, 2); Array array = Array.CreateInstance(t, n); for (int k = 0; k < n; k++) { LuaNativeMethods.lua_rawgeti(ptr, 2, k + 1); object obj = LuaObject.CheckVar(ptr, -1); array.SetValue(LuaObject.ChangeType(obj, t), k); LuaNativeMethods.lua_pop(ptr, 1); } LuaObject.PushValue(ptr, true); LuaObject.PushValue(ptr, array); return(2); } catch (Exception e) { return(Error(ptr, e)); } }
public static int CreateClass(IntPtr ptr) { try { string cls; CheckType(ptr, 1, out cls); Type t = LuaObject.FindType(cls); if (t == null) { return(Error(ptr, string.Format("Can't find {0} to create", cls))); } ConstructorInfo[] cis = t.GetConstructors(); ConstructorInfo target = null; for (int n = 0; n < cis.Length; n++) { ConstructorInfo ci = cis[n]; if (LuaObject.MatchType(ptr, LuaNativeMethods.lua_gettop(ptr), 2, ci.GetParameters())) { target = ci; break; } } if (target != null) { ParameterInfo[] pis = target.GetParameters(); object[] args = new object[pis.Length]; for (int n = 0; n < pis.Length; n++) { args[n] = LuaObject.ChangeType(LuaObject.CheckVar(ptr, n + 2), pis[n].ParameterType); } object ret = target.Invoke(args); LuaObject.PushValue(ptr, true); LuaObject.PushVar(ptr, ret); return(2); } LuaObject.PushValue(ptr, true); return(1); } catch (Exception e) { return(Error(ptr, e)); } }
private object TopObjects(int args) { if (args == 0) { return(null); } else if (args == 1) { object o = LuaObject.CheckVar(this.thread, -1); return(o); } else { object[] o = new object[args]; for (int n = 1; n <= args; n++) { o[n - 1] = LuaObject.CheckVar(this.thread, n); } return(o); } }
public object GetObject(IntPtr ptr, int p) { p = LuaNativeMethods.lua_absindex(ptr, p); return(LuaObject.CheckVar(ptr, p)); }