public LuaObject findObject(String name) { using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(this)) { return(myGlobalTable[name]); } }
public LuaObject call(params LuaObject[] parameters) { if (myType != LuaTypes.FUNCTION) { return(null); } using (LuaAutoStackCleaner auto = new LuaAutoStackCleaner(myState)) { LuaDLL.lua_pushcfunction(myState.statePtr, theErrorFunction); int errorIndex = LuaDLL.lua_gettop(myState.statePtr); push(); for (int i = 0; i < parameters.Length; i++) { parameters[i].push(); } int error = LuaDLL.lua_pcall(myState.statePtr, parameters.Length, LuaDLL.LUA_MULTRET, errorIndex); if (error != 0) { Console.Write("Error running function: "); Console.Write(LuaDLL.lua_tostring(myState.statePtr, -1)); } return(new LuaObject(myState, -1)); } }
public LuaObject createTable() { using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(this)) { LuaDLL.lua_createtable(myStatePtr, 0 /*narr*/, 0 /*nrec*/); return(new LuaObject(this, -1)); } }
//this should only be used for luaObjects that are arrays public int count() { using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); return(LuaDLL.lua_rawlen(myState.statePtr, -1)); } }
public bool contains(String name) { if (myType != LuaTypes.TABLE) { return(false); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); String[] pieces = name.Split('.'); foreach (String s in pieces) { if (s.Contains("[") == true) { int arrayLocEnd = s.IndexOf("]"); String tableName = s.Substring(0, s.IndexOf("]")); LuaDLL.lua_pushstring(myState.statePtr, tableName); LuaDLL.lua_gettable(myState.statePtr, -2); if (LuaDLL.lua_isnil(myState.statePtr, -1) == true) { return(false); } string indexName = s.Substring(s.IndexOf("["), s.IndexOf("]")); int n; bool isNumeric = int.TryParse(indexName, out n); if (isNumeric == true) { LuaDLL.lua_pushnumber(myState.statePtr, n); } else { LuaDLL.lua_pushstring(myState.statePtr, indexName); } LuaDLL.lua_gettable(myState.statePtr, -2); if (stackValueOk() == false) { return(false); } } else { LuaDLL.lua_pushstring(myState.statePtr, s); LuaDLL.lua_gettable(myState.statePtr, -2); if (LuaDLL.lua_isnil(myState.statePtr, -1) == true) { return(false); } } } return(LuaDLL.lua_isnil(myState.statePtr, -1) == false); } }
public T get <T>(String index) { if (myType != DataType.TABLE) { throw new Exception("Cannot get field on non-table"); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); String[] pieces = index.Split('.'); foreach (String s in pieces) { if (s.Contains("[") == true) { int arrayLocBegin = s.IndexOf("["); int arrayLocEnd = s.IndexOf("]"); String tableName = s.Substring(0, arrayLocBegin); LuaDLL.lua_pushstring(myState.statePtr, tableName); LuaDLL.lua_gettable(myState.statePtr, -2); if (LuaDLL.lua_isnil(myState.statePtr, -1) == true) { return((T)Convert.ChangeType(null, typeof(T))); } string indexName = s.Substring(arrayLocBegin + 1, arrayLocEnd - arrayLocBegin - 1); int n; bool isNumeric = int.TryParse(indexName, out n); if (isNumeric == true) { LuaDLL.lua_pushnumber(myState.statePtr, n); } else { LuaDLL.lua_pushstring(myState.statePtr, indexName); } LuaDLL.lua_gettable(myState.statePtr, -2); if (stackValueOk() == false) { return((T)Convert.ChangeType(null, typeof(T))); } } else { LuaDLL.lua_pushstring(myState.statePtr, s); LuaDLL.lua_gettable(myState.statePtr, -2); } } T temp = myState.getValue <T>(-1); LuaDLL.lua_pop(myState.statePtr, 2); return(temp); } }
public bool contains(int index) { if (myType != LuaTypes.TABLE) { return(false); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); LuaDLL.lua_pushinteger(myState.statePtr, index); LuaDLL.lua_gettable(myState.statePtr, -2); return(LuaDLL.lua_isnil(myState.statePtr, -1) == false); } }
public void set <T>(T value, int index) { if (myType != LuaTypes.TABLE) { Console.WriteLine("Cannot set field on non-table LuaObject"); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); LuaDLL.lua_pushnumber(myState.statePtr, index); myState.pushValue <T>(value); LuaDLL.lua_settable(myState.statePtr, -3); } }
public void set <T>(T value, String index) { if (myType != DataType.TABLE) { throw new Exception("Cannot set field on non-table"); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); LuaDLL.lua_pushstring(myState.statePtr, index); myState.pushValue <T>(value); LuaDLL.lua_settable(myState.statePtr, -3); } }
public void set <T>(T value, String index) { if (myType != LuaTypes.TABLE) { Console.WriteLine("Cannot set field on non-table LuaObject"); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); String s = (String)Convert.ChangeType(value, typeof(String)); LuaDLL.lua_pushstring(myState.statePtr, s); myState.pushValue <T>(value); LuaDLL.lua_settable(myState.statePtr, -3); } }
public T get <T>(int index) { if (myType != LuaTypes.TABLE) { return((T)Convert.ChangeType(0, typeof(T))); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); LuaDLL.lua_pushnumber(myState.statePtr, index); LuaDLL.lua_gettable(myState.statePtr, -2); T temp = myState.getValue <T>(-1); LuaDLL.lua_pop(myState.statePtr, 2); return(temp); } }
public T get <T>(int index) { if (myType != DataType.TABLE) { throw new Exception("Cannot set field on non-table"); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); LuaDLL.lua_pushnumber(myState.statePtr, index); LuaDLL.lua_gettable(myState.statePtr, -2); T temp = myState.getValue <T>(-1); LuaDLL.lua_pop(myState.statePtr, 2); return(temp); } }
public LuaObject call(params LuaValue[] parameters) { if (myType != DataType.FUNCTION) { return(null); } using (LuaAutoStackCleaner auto = new LuaAutoStackCleaner(myState)) { LuaDLL.lua_pushcfunction(myState.statePtr, theErrorFunction); int errorIndex = LuaDLL.lua_gettop(myState.statePtr); push(); for (int i = 0; i < parameters.Length; i++) { switch (parameters[i].type()) { case DataType.NIL: LuaDLL.lua_pushnil(myState.statePtr); break; case DataType.BOOL: LuaDLL.lua_pushboolean(myState.statePtr, (int)parameters[i]); break; case DataType.INT: LuaDLL.lua_pushnumber(myState.statePtr, (double)parameters[i]); break; case DataType.FLOAT: LuaDLL.lua_pushnumber(myState.statePtr, (double)parameters[i]); break; case DataType.DOUBLE: LuaDLL.lua_pushnumber(myState.statePtr, (double)parameters[i]); break; case DataType.STRING: LuaDLL.lua_pushstring(myState.statePtr, (string)parameters[i]); break; case DataType.TABLE: LuaObject obj = (LuaObject)parameters[i]; obj.push(); break; } } int error = LuaDLL.lua_pcall(myState.statePtr, parameters.Length, LuaDLL.LUA_MULTRET, errorIndex); if (error != 0) { Console.Write("Error running function: "); Console.Write(LuaDLL.lua_tostring(myState.statePtr, -1)); } return(new LuaObject(myState, -1)); } }
public LuaObject this[int index] { get { if (myType != LuaTypes.TABLE) { return(null); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); LuaDLL.lua_pushnumber(myState.statePtr, index); LuaDLL.lua_gettable(myState.statePtr, -2); LuaObject temp = new LuaObject(myState, -1); LuaDLL.lua_pop(myState.statePtr, 2); return(temp); } } }
public LuaObject this[string index] { get { if (myType != LuaTypes.TABLE) { return(null); } using (LuaAutoStackCleaner cleaner = new LuaAutoStackCleaner(myState)) { push(); String[] pieces = index.Split('.'); foreach (String s in pieces) { if (s.Contains("[") == true) { int arrayLocEnd = s.IndexOf("]"); String tableName = s.Substring(0, s.IndexOf("]")); LuaDLL.lua_pushstring(myState.statePtr, tableName); LuaDLL.lua_gettable(myState.statePtr, -2); if (LuaDLL.lua_isnil(myState.statePtr, -1) == true) { return(null); } string indexName = s.Substring(s.IndexOf("["), s.IndexOf("]")); int n; bool isNumeric = int.TryParse(indexName, out n); if (isNumeric == true) { LuaDLL.lua_pushnumber(myState.statePtr, n); } else { LuaDLL.lua_pushstring(myState.statePtr, indexName); } LuaDLL.lua_gettable(myState.statePtr, -2); if (stackValueOk() == false) { return(null); } } else { LuaDLL.lua_pushstring(myState.statePtr, s); LuaDLL.lua_gettable(myState.statePtr, -2); } } LuaObject temp = new LuaObject(myState, -1); return(temp); } } set { throw new Exception("Set not implemented"); } }