public static int LuaIndex(IntPtr ptr) { try { Array a = (Array)CheckSelf(ptr); if (LuaNativeMethods.lua_type(ptr, 2) == LuaTypes.TYPE_STRING) { string mn; CheckType(ptr, 2, out mn); ArrayPropFunction fun; if (propertyMethods.TryGetValue(mn, out fun)) { LuaObject.PushValue(ptr, true); return(fun(ptr, a) + 1); } else { throw new Exception("Can't find property named " + mn); } } else { int i; CheckType(ptr, 2, out i); LuaObject.Assert(i > 0, "index base 1"); LuaObject.PushValue(ptr, true); LuaObject.PushVar(ptr, a.GetValue(i - 1)); return(2); } } catch (Exception e) { return(Error(ptr, e)); } }
public object Call(object a1) { int error = LuaObject.PushTry(state.StatePointer); LuaObject.PushVar(state.StatePointer, a1); if (InnerCall(1, error)) { return(state.TopObjects(error - 1)); } return(null); }
public void SetObject(string[] remainingPath, object o) { int top = LuaNativeMethods.lua_gettop(statePointer); for (int i = 0; i < remainingPath.Length - 1; i++) { LuaNativeMethods.lua_pushstring(statePointer, remainingPath[i]); LuaNativeMethods.lua_gettable(statePointer, -2); } LuaNativeMethods.lua_pushstring(statePointer, remainingPath[remainingPath.Length - 1]); LuaObject.PushVar(statePointer, o); LuaNativeMethods.lua_settable(statePointer, -3); LuaNativeMethods.lua_settop(statePointer, top); }
public object Call(params object[] args) { int error = LuaObject.PushTry(state.StatePointer); for (int n = 0; args != null && n < args.Length; n++) { LuaObject.PushVar(VariablePointer, args[n]); } if (InnerCall(args != null ? args.Length : 0, error)) { return(state.TopObjects(error - 1)); } return(null); }
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)); } }
public static int ToTable(IntPtr ptr, Array o) { if (o == null) { LuaNativeMethods.lua_pushnil(ptr); return(1); } LuaNativeMethods.lua_createtable(ptr, o.Length, 0); for (int n = 0; n < o.Length; n++) { LuaObject.PushVar(ptr, o.GetValue(n)); LuaNativeMethods.lua_rawseti(ptr, -2, n + 1); } return(1); }
public void SetObject(int reference, int index, object o) { if (index >= 1) { LuaNativeMethods.lua_getref(statePointer, reference); LuaObject.PushVar(statePointer, o); LuaNativeMethods.lua_rawseti(statePointer, -2, index); LuaNativeMethods.lua_pop(statePointer, 1); } else { LuaNativeMethods.lua_getref(statePointer, reference); LuaNativeMethods.lua_pushinteger(statePointer, index); LuaObject.PushVar(statePointer, o); LuaNativeMethods.lua_settable(statePointer, -3); LuaNativeMethods.lua_pop(statePointer, 1); } }
public static int _iter(IntPtr ptr) { object obj = CheckObj(ptr, LuaNativeMethods.lua_upvalueindex(1)); IEnumerator it = (IEnumerator)obj; if (it.MoveNext()) { LuaObject.PushVar(ptr, it.Current); return(1); } else { if (obj is IDisposable) { ((IDisposable)obj).Dispose(); } } return(0); }
public static int CreateAction(IntPtr ptr) { try { LuaFunction func; CheckType(ptr, 1, out func); Action action = new Action(() => { func.Call(); }); LuaObject.PushValue(ptr, true); LuaObject.PushVar(ptr, action); return(2); } catch (Exception e) { return(Error(ptr, e)); } }