public override bool TryConvert(ConvertBinder binder, out object result) { result = null; if (binder.Type == typeof(object[])) { result = _array; return(true); } if (_array.Length != 1) { return(false); } if (_array[0].GetType() == typeof(LuaTable) || _array[0].GetType() == typeof(LuaFunction)) { result = LuaHelper.UnWrapObject(_array[0], _state); return(true); } if (_array[0].GetType() != binder.Type) { return(false); } result = Convert.ChangeType(_array[0], binder.Type); return(true); }
public override bool TryGetMember(GetMemberBinder binder, out object result) { result = null; if (!int.TryParse(binder.Name, out var index)) { return(false); } if (index >= _array.Length) { return(false); } result = LuaHelper.UnWrapObject(_array[index], _state); return(true); }
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) { result = null; if (!int.TryParse(indexes[0].ToString(), out var index)) { return(false); } if (index >= _array.Length) { return(false); } result = LuaHelper.UnWrapObject(_array[index], _state); return(true); }
private object GetTableValue(string name) { var val = _table[name]; if (val != null) { return(LuaHelper.UnWrapObject(val, _state, _path + "." + name)); } //not found, check __index of metatable var func = GetMetaFunction("index"); if (func != null) //metatable and metamethod set { return(LuaHelper.UnWrapObject(func.Call(_table, name)[0], _state, _path + "." + name)); } return(null); }
private object GetLuaValue(string name) { return(LuaHelper.UnWrapObject(Lua[name], Lua, name)); }
public dynamic GetMetatable() { return(LuaHelper.UnWrapObject( _state.DoString($"return getmetatable({_path})", "DynamicLua internal operation")[0], _state)); }