public LuaObject(object value) { if (value == null) { type = ELuaItemType.Nil; } else { Type valueType = value.GetType(); if (valueType.IsArray || (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(List <>))) { type = ELuaItemType.Table; value_table = new LuaTable(); foreach (var item in (IList)value) { value_table.AddItem(item); } } else { if (valueType == typeof(int)) { type = ELuaItemType.Int; value_int = (int)value; } else if (valueType == typeof(long)) { type = ELuaItemType.Long; value_long = (long)value; } else if (valueType == typeof(float)) { type = ELuaItemType.Float; value_float = (float)value; } else if (valueType == typeof(bool)) { type = ELuaItemType.Boolean; value_boolean = (bool)value; } else if (valueType == typeof(string)) { value_str = (string)value; if (value_str.IndexOf("function") >= 0 && value_str.IndexOf("end") >= 0) { type = ELuaItemType.Function; } else { type = ELuaItemType.String; } } else if (valueType == typeof(LuaTable)) { type = ELuaItemType.Table; value_table = (LuaTable)value; } else { type = ELuaItemType.Nil; } } } }
public LuaObject() { type = ELuaItemType.nil; }
public LuaObject(LuaTable value) { type = ELuaItemType.Table; value_table = value; }
public LuaObject(bool value) { type = ELuaItemType.Boolean; value_boolean = value; }
public LuaObject(int value) { type = ELuaItemType.Num; value_num = value; }
public LuaObject(string value) { type = ELuaItemType.String; value_str = value; }