public override LuaValue Execute(LuaTable enviroment, out bool isBreak) { LuaTable table = enviroment; if (this.Name.MethodName == null) { for (int i = 0; i < this.Name.FullName.Count - 1; i++) { LuaValue obj = enviroment.GetValue(this.Name.FullName[i]); table = obj as LuaTable; if (table == null) { throw new Exception("Not a table: " + this.Name.FullName[i]); } } table.SetNameValue( this.Name.FullName[this.Name.FullName.Count - 1], this.Body.Evaluate(enviroment)); } else { for (int i = 0; i < this.Name.FullName.Count; i++) { LuaValue obj = enviroment.GetValue(this.Name.FullName[i]); table = obj as LuaTable; if (table == null) { throw new Exception("Not a table " + this.Name.FullName[i]); } } this.Body.ParamList.NameList.Insert(0, "self"); table.SetNameValue( this.Name.MethodName, this.Body.Evaluate(enviroment)); } isBreak = false; return null; }
public override LuaValue Evaluate(LuaTable environment) { return environment.GetValue(Name); }
public static LuaValue GetKeyValue(LuaValue baseValue, LuaValue key) { LuaTable table = baseValue as LuaTable; if (table != null) { return(table.GetValue(key)); } else { LuaUserdata userdata = baseValue as LuaUserdata; if (userdata != null) { if (userdata.MetaTable != null) { LuaValue index = userdata.MetaTable.GetValue("__index"); if (index != null) { LuaFunction func = index as LuaFunction; if (func != null) { return(func.Invoke(new LuaValue[] { baseValue, key })); } else { return(GetKeyValue(index, key)); } } } } //[PixelCrushers] Changed wording: throw new Exception(string.Format("Lookup of field '{0}' in the table element failed because the table element itself isn't in the table.", key.Value)); } }
public static LuaValue GetKeyValue(LuaValue baseValue, LuaValue key) { LuaTable table = baseValue as LuaTable; if (table != null) { return(table.GetValue(key)); } else { LuaUserdata userdata = baseValue as LuaUserdata; if (userdata != null) { if (userdata.MetaTable != null) { LuaValue index = userdata.MetaTable.GetValue("__index"); if (index != null) { LuaFunction func = index as LuaFunction; if (func != null) { return(func.Invoke(new LuaValue[] { baseValue, key })); } else { return(GetKeyValue(index, key)); } } } } throw new Exception(string.Format("Access field '{0}' from not a table.", key.Value)); } }
public override LuaValue Execute(LuaTable enviroment, out bool isBreak) { LuaTable table = enviroment; if (Name.MethodName == null) { for (int i = 0; i < Name.FullName.Count - 1; i++) { LuaValue obj = enviroment.GetValue(Name.FullName[i]); table = obj as LuaTable; if (table == null) { throw new Exception("Not a table: " + Name.FullName[i]); } } table.SetNameValue( Name.FullName[Name.FullName.Count - 1], Body.Evaluate(enviroment)); } else { for (int i = 0; i < Name.FullName.Count; i++) { LuaValue obj = enviroment.GetValue(Name.FullName[i]); table = obj as LuaTable; if (table == null) { throw new Exception("Not a table " + Name.FullName[i]); } } Body.ParamList.NameList.Insert(0, "self"); table.SetNameValue( Name.MethodName, Body.Evaluate(enviroment)); } isBreak = false; return(null); }
/// @endcond /// <summary> /// Gets the value with the specified string key. Returns a standard type such as /// <c>string</c>, <c>float</c>, <c>bool</c>, or <c>null</c>. If the value /// is a table, it returns a LuaTableWrapper around it. /// </summary> /// <param name="key">Key.</param> public object this[string key] { get { if (luaTable == null) { if (DialogueDebug.logErrors) { Debug.LogError(string.Format("{0}: Lua table is null; lookup[{1}] failed", new object[] { DialogueDebug.Prefix, key })); } return(null); } LuaValue luaValue = LuaNil.Nil; if (luaTable.Length > 0) { // Get list value: luaValue = luaTable.GetValue(Tools.StringToInt(key)); } else { // Get dictionary value: LuaValue luaValueKey = luaTable.GetKey(key); if (luaValueKey == LuaNil.Nil) { //--- Suppressed: if (DialogueDebug.LogErrors) Debug.LogError(string.Format("{0}: Lua table does not contain key [{1}]", new string[] { DialogueDebug.Prefix, key })); return(null); } luaValue = luaTable.GetValue(key); } if (luaValue is LuaTable) { return(new LuaTableWrapper(luaValue as LuaTable)); } else { return(LuaInterpreterExtensions.LuaValueToObject(luaValue)); } } }
private LuaValue GetValueFromMetaTable(LuaValue key) { LuaValue indexer = this.MetaTable.GetValue("__index"); LuaTable table = indexer as LuaTable; if (table != null) { return(table.GetValue(key)); } LuaFunction function = indexer as LuaFunction; if (function != null) { return(function.Function.Invoke(new LuaValue[] { key })); } return(LuaNil.Nil); }
private LuaValue GetValueFromMetaTable(string name) { LuaValue indexer = MetaTable.GetValue("__index"); LuaTable table = indexer as LuaTable; if (table != null) { return(table.GetValue(name)); } LuaFunction function = indexer as LuaFunction; if (function != null) { return(function.Function.Invoke(new LuaValue[] { new LuaString(name) })); } return(LuaNil.Nil); }
private static LuaFunction GetMetaFunction(string name, LuaValue leftValue, LuaValue rightValue) { LuaTable left = leftValue as LuaTable; if (left != null) { LuaFunction func = left.GetValue(name) as LuaFunction; if (func != null) { return(func); } } LuaTable right = rightValue as LuaTable; if (right != null) { return(right.GetValue(name) as LuaFunction); } return(null); }
public override LuaValue Evaluate(LuaTable enviroment) { return(enviroment.GetValue(this.Name)); }