XTable NextObject() { XTable result = new XTable(); /* Peek to see if this is the empty object. */ char first = this.NextCleanChar(); if (first == '}') { return(result); } else if (first != '\0') { mPosition--; } while (true) { Object name = this.NextName(); /* * Expect the name/value separator to be either a colon ':', an * equals sign '=', or an arrow "=>". The last two are bogus but we * include them because that's what the original implementation did. */ char separator = this.NextCleanChar(); if (separator != ':' && separator != '=') { // error: "Expected ':' after " + name return(null); } if (mPosition < mSource.Length && mSource.Substring(mPosition, 1).ToCharArray()[0] == '>') { mPosition++; } result[(string)name] = this.NextValue(); switch (this.NextCleanChar()) { case '}': return(result); case ';': case ',': continue; default: // error: Unterminated object return(null); } } }
public GameObject OpenUI(int canvasIndex, string uiName, XTable attr = null) { if (canvasIndex < 0 || canvasIndex >= this.canvasList.Count) { return(null); } Canvas canvas = this.canvasList[canvasIndex]; GameObject ui = this.FindUI(canvas, uiName); if (ui == null) { ui = this.CreateUI(canvas, uiName); } return(this.OpenUI(ui, attr)); }
public async Task <bool> SetLocale(Locale locale) { string url = Path.Combine(baseURL, String.Format("{0}.json", locale.ToString())); var www = UnityWebRequest.Get(url); await www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.LogError(www.result.ToString()); return(false); } string text = www.downloadHandler.text; var newData = XTableExchange.json.StringToTable(text); this.data = newData; return(true); }
public object GetValue(int index) { string type = mLuaState.L_TypeName(index); switch (type) { case "number": return(mLuaState.ToNumber(index)); case "boolean": return(mLuaState.ToBoolean(index)); case "string": string utf8 = mLuaState.ToString(index); return(XCSharp.DecodeUTF8(utf8)); case "function": return(mLuaState.L_Ref(UniLua.LuaDef.LUA_REGISTRYINDEX)); case "table": XTable table = new XTable(); { mLuaState.PushValue(index); int t = mLuaState.GetTop(); mLuaState.PushNil(); while (mLuaState.Next(t)) { object key = this.GetValue(-2); object val = this.GetValue(-1); table[key] = val; mLuaState.Pop(1); } mLuaState.Pop(1); } return(table); default: return(mLuaState.ToUserData(index)); } }
public static object TableObject(XTable table, Type type) { if (table == null || table.Count == 0) { return(null); } object o = Activator.CreateInstance(type); FieldInfo[] fields = o.GetType().GetFields(); foreach (FieldInfo f in fields) { Type t = f.FieldType; string n = f.Name; object v = f.GetValue(o); switch (t.FullName) { case "System.Boolean": case "System.Char": case "System.Byte": case "System.SByte": case "System.Int16": case "System.UInt16": case "System.Int32": case "System.UInt32": case "System.Int64": case "System.UInt64": case "System.Single": case "System.Double": case "System.Decimal": case "System.String": case "XTable": v = table[n]; break; default: v = XTable.TableObject(table[n] as XTable, t); break; } f.SetValue(o, v); } return(o); }
public static XTable ObjectTable(object o) { XTable table = new XTable(); if (o == null) { return(table); } FieldInfo[] fields = o.GetType().GetFields(); foreach (FieldInfo f in fields) { Type t = f.FieldType; string n = f.Name; object v = f.GetValue(o); switch (t.FullName) { case "System.Boolean": case "System.Char": case "System.Byte": case "System.SByte": case "System.Int16": case "System.UInt16": case "System.Int32": case "System.UInt32": case "System.Int64": case "System.UInt64": case "System.Single": case "System.Double": case "System.Decimal": case "System.String": case "XTable": table[n] = v; break; default: table[n] = XTable.ObjectTable(v); break; } } return(table); }
public GameObject OpenUI(GameObject ui, XTable attr = null) { if (ui == null) { return(null); } GUIBehavior behavior = ui.GetComponent <GUIBehavior>(); if (behavior != null) { if (attr != null) { behavior.attribute = attr; } behavior.Open(); } return(ui); }
public int PushValue(object o) { if (o == null) { mLuaState.PushNil(); return(1); } Type t = o.GetType(); switch (t.FullName) { case "System.Boolean": { mLuaState.PushBoolean((bool)o); return(1); } case "System.Char": { mLuaState.PushString(((char)o).ToString()); return(1); } case "System.Byte": { mLuaState.PushNumber((byte)o); return(1); } case "System.SByte": { mLuaState.PushNumber((sbyte)o); return(1); } case "System.Int16": { mLuaState.PushNumber((short)o); return(1); } case "System.UInt16": { mLuaState.PushNumber((ushort)o); return(1); } case "System.Int32": { mLuaState.PushNumber((int)o); return(1); } case "System.UInt32": { mLuaState.PushNumber((uint)o); return(1); } case "System.Int64": { mLuaState.PushUInt64((ulong)o); return(1); } case "System.UInt64": { mLuaState.PushUInt64((ulong)o); return(1); } case "System.Single": { mLuaState.PushNumber((float)o); return(1); } case "System.Double": { mLuaState.PushNumber((double)o); return(1); } case "System.Decimal": { mLuaState.PushLightUserData((decimal)o); return(1); } case "System.String": { string utf8 = XCSharp.EncodeUTF8(o as string); mLuaState.PushString(utf8); return(1); } case "System.Object": { mLuaState.PushLightUserData((object)o); return(1); } case "XTable": { mLuaState.NewTable(); XTable table = o as XTable; foreach (string key in table.Nodes.Keys) { object val = table.Nodes[key]; this.PushValue(key); this.PushValue(val); mLuaState.RawSet(-3); } mLuaState.RawSet(-3); return(1); } default: { mLuaState.PushLightUserData((object)o); return(1); } } }
public XArchive() { this.mContents = new XTable(); }
public static void TableToValue(XTable table, ref Vector3 value) { value.x = table.Float("x"); value.y = table.Float("y"); value.z = table.Float("z"); }