void Awake() { // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突 object[] obj = luaEnv.DoString(FileUtils.ReadFileContent(luaScript), luaScript); if (obj != null && obj.Length > 0) { scriptEnv = obj[0] as LuaTable; } if (scriptEnv == null) { return; } print(obj.Length); var data = scriptEnv.GetInPath <LuaTable>("data"); var result = LuaConvert.ConvertToObject(data); var ret = MessagePackSerializer.ToJson(result); print(ret); var body = MessagePackSerializer.FromJson(ret); LogTool.Instance.ToStringAll(body); // Action luaAwake = scriptEnv.Get<Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); }
/// <inheritdoc /> public override void WriteValue(string value) { base.WriteValue(value); if (value == null) { writer.Write(LuaConvert.Nil); } else { LuaConvert.WriteString(writer, value); } }
/// <inheritdoc /> public override void WriteValue(Uri value) { base.WriteValue(value); if (value == null) { writer.Write(LuaConvert.Nil); } else { writer.Write(LuaConvert.ToString(value)); } }
public void ToStringTest() { Assert.Equal(@"""test\a\b\r\n\""abc""", LuaConvert.ToString("test\a\b\r\n\"abc")); Assert.Equal(@"'abc""def'", LuaConvert.ToString("abc\"def", "'")); Assert.Equal(@"[[test]]", LuaConvert.ToString("test", "[[")); Assert.Equal(@"[==[test]==]", LuaConvert.ToString("test", "[==[")); Assert.Equal(@"[==========[test]==========]", LuaConvert.ToString("test", "[==========[")); Assert.Equal("-12345", LuaConvert.ToString(-12345)); Assert.Equal("123.45", LuaConvert.ToString(123.45)); Assert.Equal(@"""http://cxuesong.com/""", LuaConvert.ToString(new Uri("http://cxuesong.com/"))); Assert.Equal("nil", LuaConvert.ToString((object)null)); Assert.Equal("-12345", LuaConvert.ToString((object)-12345)); Assert.Equal("123.45", LuaConvert.ToString((object)123.45)); }
/// <inheritdoc /> public override void WritePropertyName(string name) { base.WritePropertyName(name); if (name.Length > 0 && name.Length < _MaxUnquotedNameLength && LuaConvert.IsValidIdentifier(name)) { writer.Write(name); } else { writer.Write('['); writer.Write(LuaConvert.ToString(name)); writer.Write(']'); } if (Formatting == Newtonsoft.Json.Formatting.Indented) { writer.Write(" ="); // base class will insert a space after = } else { writer.Write('='); } }
/// <inheritdoc /> public override void WriteValue(TimeSpan value) { base.WriteValue(value); writer.Write(LuaConvert.ToString(value)); }
/// <inheritdoc /> public override void WriteValue(Guid value) { base.WriteValue(value); writer.Write(LuaConvert.ToString(value.ToString("D"))); }
/// <inheritdoc /> public override void WriteValue(DateTimeOffset value) { base.WriteValue(value); writer.Write(LuaConvert.ToString(value)); }
/// <inheritdoc /> public override void WriteValue(decimal value) { base.WriteValue(value); writer.Write(LuaConvert.ToString(value)); }