Ejemplo n.º 1
0
    public void Init()
    {
        _luaState = LuaAPI.NewState();
        _luaState.L_OpenLibs();
        _luaState.L_RequireF("LuaLib", LuaLib.Init, false);
        LuaLib.InitGlobal(_luaState);
        LuaLib.RegisterLightUserDataLuaInterface();
        _luaState.Pop(_luaState.GetTop());
        // 添加错误log函数
        _luaState.PushCSharpFunction(Traceback);
        _traceBackIndex = _luaState.GetTop();
        // 加载Constants.lua
        var status = _luaState.L_DoFile("Constants.lua");

        if (status != ThreadStatus.LUA_OK)
        {
            throw new Exception(_luaState.ToString(-1));
        }
        InitGlobalFields();
    }