예제 #1
0
    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);
    }
예제 #2
0
 /// <inheritdoc />
 public override void WriteValue(string value)
 {
     base.WriteValue(value);
     if (value == null)
     {
         writer.Write(LuaConvert.Nil);
     }
     else
     {
         LuaConvert.WriteString(writer, value);
     }
 }
예제 #3
0
 /// <inheritdoc />
 public override void WriteValue(Uri value)
 {
     base.WriteValue(value);
     if (value == null)
     {
         writer.Write(LuaConvert.Nil);
     }
     else
     {
         writer.Write(LuaConvert.ToString(value));
     }
 }
예제 #4
0
 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));
 }
예제 #5
0
        /// <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('=');
            }
        }
예제 #6
0
 /// <inheritdoc />
 public override void WriteValue(TimeSpan value)
 {
     base.WriteValue(value);
     writer.Write(LuaConvert.ToString(value));
 }
예제 #7
0
 /// <inheritdoc />
 public override void WriteValue(Guid value)
 {
     base.WriteValue(value);
     writer.Write(LuaConvert.ToString(value.ToString("D")));
 }
예제 #8
0
 /// <inheritdoc />
 public override void WriteValue(DateTimeOffset value)
 {
     base.WriteValue(value);
     writer.Write(LuaConvert.ToString(value));
 }
예제 #9
0
 /// <inheritdoc />
 public override void WriteValue(decimal value)
 {
     base.WriteValue(value);
     writer.Write(LuaConvert.ToString(value));
 }