示例#1
0
        static void HookCallback(IntPtr p, IntPtr ar)
        {
            var state = Lua.FromIntPtr(p);
            var debug = LuaDebug.FromIntPtr(ar);

            Assert.NotNull(state, "#state shouldn't be null");
            Assert.NotNull(debug, "#debug shouldn't be null");

            if (debug.Event != LuaHookEvent.Line)
            {
                return;
            }

            state.GetStack(0, ar);

            if (!state.GetInfo("Snlu", ar))
            {
                return;
            }

            debug = LuaDebug.FromIntPtr(ar);
            string source = debug.Source.Substring(1);

            source = System.IO.Path.GetFileName(source);
            hookLog.AppendLine($"{source}:{debug.CurrentLine} ({debug.What})");
        }
示例#2
0
文件: Runtime.cs 项目: MultHub/Eight
        public static bool Init()
        {
            _quit    = false;
            LuaState = new Lua {
                Encoding = Encoding.UTF8
            };

            LuaState.PushString($"Eight {Eight.Version}");
            LuaState.SetGlobal("_HOST");

            LuaState.SetWarningFunction(WarnFunction, IntPtr.Zero);

            DoLibs();

            State = LuaState.NewThread();

            State.SetHook((luaState, ar) => {
                var state = Lua.FromIntPtr(luaState);

                var arg = LuaDebug.FromIntPtr(ar);

                if (arg.Event == LuaHookEvent.Count)
                {
                    if (Event.OutOfSync && !_killed)
                    {
                        _killed = true;
                        if (Eight.Flags["out_of_sync_error"])
                        {
                            State.Error("out of sync");
                        }
                    }
                }
            }, LuaHookMask.Count, 10000);

            if (!File.Exists("Lua/boot.lua"))
            {
                Console.WriteLine("Could not find boot.lua");
                Eight.Crash("Could not find bios.lua!", "Is Eight installed correctly?");
                return(false);
            }

            var biosContent = File.ReadAllText("Lua/boot.lua");

            var status = State.LoadString(biosContent, "@BOOT");

            if (status != LuaStatus.OK)
            {
                var error = State.ToString(-1);
                Console.WriteLine("Lua Load Exception: {0}", error);
                return(false);
            }

            return(true);
        }