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 static int LuaNewIndex(IntPtr ptr) { try { Array a = (Array)CheckSelf(ptr); int i; CheckType(ptr, 2, out i); LuaObject.Assert(i > 0, "index base 1"); object o = CheckVar(ptr, 3); Type et = a.GetType().GetElementType(); a.SetValue(LuaObject.ChangeType(o, et), i - 1); return(LuaObject.Ok(ptr)); } catch (Exception e) { return(Error(ptr, e)); } }