Exemplo n.º 1
0
    public void Init()
    {
        lua_ = LuaAPI.NewState();
        lua_.L_OpenLibs();
        lua_.L_RequireF(GameScript.LIB_NAME, GameScript.OpenLib, false);
        lua_.L_RequireF(Sys.LIB_NAME, Sys.OpenLib, true);
        lua_.L_RequireF(Global_.LIB_NAME, Global_.OpenLib, true);
        #region registGlobal

        GameScript.RegistGlobalEnum(typeof(ScriptGameEvent));
        GameScript.RegistGlobalEnum(typeof(GuidePointerRotateType));
        GameScript.RegistGlobalEnum(typeof(BattlePosition));
        GameScript.RegistGlobalEnum(typeof(PropertyType));
        GameScript.RegistGlobalEnum(typeof(OrderParamType));
        GameScript.RegistGlobalEnum(typeof(GroupType));
        GameScript.RegistGlobalEnum(typeof(StateType));
        GameScript.RegistGlobalEnum(typeof(ItemMainType));
        GameScript.RegistGlobalEnum(typeof(ItemSubType));
        GameScript.RegistGlobalEnum(typeof(TogetherStateType));
        GameScript.RegistGlobalEnum(typeof(StateType));
        GameScript.RegistGlobalEnum(typeof(GuideAimType));
        GameScript.RegistGlobalEnum(typeof(WeaponType));
        GameScript.RegistGlobalEnum(typeof(JobType));
        GameScript.RegistGlobalEnum(typeof(Constant));
        GameScript.RegistGlobalEnum(typeof(BattleJudgeType));
        GameScript.RegistGlobalEnum(typeof(SenseActorType));
        #endregion

        LoadScript(luaEntryFile_);
    }
Exemplo n.º 2
0
    public void InitLuaMgr( )
    {
        m_luaState = LuaAPI.NewState();
        m_luaState.L_OpenLibs();

        ToolLib.LuaOpenCommonLib(m_luaState);
    }
Exemplo n.º 3
0
    void Awake()
    {
        if (_lua == null)
        {
            _lua = LuaAPI.NewState();                    // создаем

            _lua.L_OpenLibs();
            _lua.L_RequireF("mylib", OpenLib, true);
            _status = _lua.L_DoFile(LuaScriptFile);

            //	throw new Exception( _lua.ToString(-1) );

            if (_status != ThreadStatus.LUA_OK)
            {
                Debug.LogError("Error parsing lua code");
            }

            if (!_lua.IsTable(-1))
            {
                throw new Exception("framework main's return value is not a table");
            }


            //	_lua.L_LoadFile (LuaScriptFile);

            mainRef = StoreMethod("main");
            //	_lua.Resume (null, 0);
            //	_lua.Pop (1);
        }
    }
    void Awake()
    {
        Debug.Log("LuaScriptController Awake");
        if (mLuaState == null)
        {
            mLuaState = LuaAPI.NewState();
            mLuaState.L_OpenLibs();
            var status = mLuaState.L_DoFile(LUA脚本入口);
            if (status != ThreadStatus.LUA_OK)
            {
                throw new Exception(mLuaState.ToString(-1));
            }
            if (!mLuaState.IsTable(-1))
            {
                throw new Exception("entry main's return value is not a table");
            }

            mAwakeRef       = StoreMethod("awake");
            mStartRef       = StoreMethod("start");
            mUpdateRef      = StoreMethod("update");
            mLateUpdateRef  = StoreMethod("late_update");
            mFixedUpdateRef = StoreMethod("fixed_update");
            mLuaState.Pop(1);
            Debug.Log("Lua Init Done");
        }
        CallMethod(mAwakeRef);
    }
Exemplo n.º 5
0
    void Awake()
    {
        Debug.Log("LuaScriptController Awake");

        if (Lua == null)
        {
            Lua = LuaAPI.NewState();
            Lua.L_OpenLibs();

            var status = Lua.L_DoFile(LuaScriptFile);
            if (status != ThreadStatus.LUA_OK)
            {
                throw new Exception(Lua.ToString(-1));
            }

            if (!Lua.IsTable(-1))
            {
                throw new Exception(
                          "framework main's return value is not a table");
            }

            AwakeRef       = StoreMethod("awake");
            StartRef       = StoreMethod("start");
            UpdateRef      = StoreMethod("update");
            LateUpdateRef  = StoreMethod("late_update");
            FixedUpdateRef = StoreMethod("fixed_update");

            Lua.Pop(1);
            Debug.Log("Lua Init Done");
        }

        CallMethod(AwakeRef);
    }
Exemplo n.º 6
0
    LuaInstance()
    {
        lua_ = LuaAPI.NewState(IntPtr.Zero);
        lua_.L_OpenLibs();
        LuaClassList.Init();

        for (int i = 0; i < 10; i++)
        {
            params_[i] = new object[i];
        }

        //Register Debug.Log
        Type     debugClassType = typeof(Debug);
        LuaClass lua_class      = RegisterLuaClass(debugClassType);

        FuncInfo[] funcInfos;
        if (LuaClassList.classes.TryGetValue(debugClassType, out funcInfos))
        {
            for (int j = 0; j < funcInfos.Length; j++)
            {
                lua_class.RegisterStaticFunction(funcInfos[j]);
            }
        }
        lua_class.EndRegisterClass();
    }
 protected void Awake()
 {
     if (mLuaState == null)
     {
         mLuaState = LuaAPI.NewState();
         mLuaState.L_OpenLibs();
         if (null != LUAEntryFileName && LUAEntryFileName.Length > 0)
         {
             var status = mLuaState.L_DoFile(LUAEntryFileName);
             if (status != ThreadStatus.LUA_OK)
             {
                 throw new Exception(mLuaState.ToString(-1));
             }
             if (!mLuaState.IsTable(-1))
             {
                 throw new Exception("entry main's return value is not a table");
             }
             string[] funcList = MethodNameList();
             if (null != funcList)
             {
                 for (int i = 0; i < funcList.Length; ++i)
                 {
                     var s = funcList[i];
                     if (mLuaFunctionRefs.ContainsKey(s))
                     {
                         mLuaFunctionRefs.Remove(s);
                     }
                     int funcRef = StoreMethod(s);
                     mLuaFunctionRefs.Add(s, funcRef);
                 }
             }
             mLuaState.Pop(1);
         }
     }
 }
Exemplo n.º 8
0
 private LuaMgr()
 {
     Env = LuaAPI.NewState();
     Env.L_OpenLibs();
     Env.L_RequireF(LuaTriggerLib.LIB_NAME, LuaTriggerLib.OpenLib, false);
     Env.L_RequireF(LuaControllerLib.LIB_NAME, LuaControllerLib.OpenLib, false);
     Env.L_RequireF(LuaDebugLib.LIB_NAME, LuaDebugLib.OpenLib, false);
 }
Exemplo n.º 9
0
    void Start()
    {
        Lua = LuaAPI.NewState();
        Lua.L_OpenLibs();
        var status = Lua.L_DoString(luastr);

        Debug.Log(status);
    }
Exemplo n.º 10
0
    private bool LUA_Init()
    {
        _lua = LuaAPI.NewState();
        _lua.L_OpenLibs();
        _lua.L_RequireF("io", this.GetComponent <ProcLibs>().OpenIOLib, true);
        _lua.L_RequireF("graph", this.GetComponent <ProcLibs>().OpenGraphicsLib, true);
        _thread = _lua.NewThread();

        return(true);
    }
Exemplo n.º 11
0
    public void PrepareLuaState()
    {
        lua_ = LuaAPI.NewState(IntPtr.Zero);
        lua_.L_OpenLibs();
#if UNITY_EDITOR || LuaDebugger
        LuaAPI.luaopen_RMDB(lua_.GetLuaPtr(), 0);
#endif
        //Register Global Class
        LuaDebug.RegisterToLua(lua_, typeof(LuaDebug));
        RegisterType(typeof(Register));
        LuaDBTable.RegisterToLua(lua_, typeof(LuaDBTable));
    }
Exemplo n.º 12
0
    public void InitializationFile(string luaScriptFile, uint storeMethodMask, OnStoreMethod storeMethod)
    {
        if (Lua != null)
        {
            return;
        }

        // 创建 Lua 虚拟机
        Lua = LuaAPI.NewState();
        // 加载基本库
        Lua.L_OpenLibs();
        // 加载 Lua 脚本文件
        ThreadStatus status = Lua.L_DoFile(luaScriptFile);

        // 捕获错误
        if (status != ThreadStatus.LUA_OK)
        {
            throw new Exception(Lua.ToString(-1));
        }
        // 确保 framework/main.lua 执行结果是一个 Lua Table
        if (!Lua.IsTable(-1))
        {
            throw new Exception("framework main's return value is not a table");
        }
        // 从 framework/main.lua 返回的 table 中读取 awake 字段指向的函数
        // 并保存到 AwakeRef 中 (可以将 AwakeRef 视为这个函数的句柄)
        if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_Awake) == LuaScriptDefine.StoreMethodMask_Awake)
        {
            AwakeRef = StoreMethod("awake");
        }
        if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_Start) == LuaScriptDefine.StoreMethodMask_Start)
        {
            StartRef = StoreMethod("start");
        }
        if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_Update) == LuaScriptDefine.StoreMethodMask_Update)
        {
            UpdateRef = StoreMethod("update");
        }
        if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_LateUpdate) == LuaScriptDefine.StoreMethodMask_LateUpdate)
        {
            LateUpdateRef = StoreMethod("late_update");
        }
        if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_FixedUpdate) == LuaScriptDefine.StoreMethodMask_FixedUpdate)
        {
            FixedUpdateRef = StoreMethod("fixed_update");
        }
        if (storeMethod != null)
        {
            storeMethod();
        }
        // 不再需要 framework/main.lua 返回的 table 了,将其从栈上弹出
        Lua.Pop(1);
    }
Exemplo n.º 13
0
 void create_state()
 {
     if (_luaState == null)
     {
         LuaFile.SetPathHook(path_hook);
         _luaState = LuaAPI.NewState();
         _luaState.L_OpenLibs();
         _luaState.L_DoString(_waitFunc);
         register_default_functions();
         register_common_libs();
         register_libs();
     }
 }
Exemplo n.º 14
0
    void initialLua()
    {
        // 创建 Lua 虚拟机
        mlua = LuaAPI.NewState();

        // 加载基本库
        mlua.L_OpenLibs();

        mlua.L_RequireF(LuaTest.LIB_NAME    // 库的名字
                        , LuaTest.OpenLib   // 库的初始化函数
                        , false             // 不默认放到全局命名空间 (在需要的地方用require获取)
                        );

        ConsoleEx.DebugLog("Lua Init Done", ConsoleEx.YELLOW);

        loadLuaFile();
    }
        protected void InitLuaLib()
        {
            if (mLuaState == null)
            {
                mLuaState = LuaAPI.NewState();
                mLuaState.L_OpenLibs();
                LuaEncLib.OpenLib(mLuaState);
            }
            string entryFileName = LUAEntryFileName;

            if (null != entryFileName && entryFileName.Length > 0)
            {
                var status = mLuaState.L_DoFile(entryFileName);
                if (status != ThreadStatus.LUA_OK)
                {
                    throw new Exception(mLuaState.ToString(-1));
                }
                if (!mLuaState.IsTable(-1))
                {
                    throw new Exception("entry main's return value is not a table");
                }
                OnEntryFileOvered(mLuaState.ToObject(-1) as LuaTable);
                string[] funcList = MethodNameList();
                if (null != funcList)
                {
                    for (int i = 0; i < funcList.Length; ++i)
                    {
                        var s = funcList[i];
                        if (mLuaFunctionRefs.ContainsKey(s))
                        {
#if !UNITY_3 && !UNITY_4 && !UNITY_5
                            FileLogMgr.OutToFileW("注册方法[{0}时发现同名的方法,删掉老的注册新的!", s);
#else
                            Debug.LogWarning("注册方法" + s + "时发现同名的方法,删掉老的注册新的!");
#endif
                            //UnStoreMethod(s, mLuaFunctionRefs[s]);
                            mLuaFunctionRefs.Remove(s);
                        }
                        int funcRef = StoreMethod(s);
                        mLuaFunctionRefs.Add(s, funcRef);
                    }
                }
                mLuaState.Pop(1);
            }
        }
Exemplo n.º 16
0
        public static LuaProto CompileFile(string filename)
        {
            // var lua = LuaAPI.NewState();
            // var reader = new BinaryReader( File.Open(filename, FileMode.Open) );
            // var p = new Parser( lua );
            // return p.Parse( reader, "@" + filename );

            var lua    = LuaAPI.NewState();
            var status = lua.L_LoadFileX(filename, null);

            if (status != ThreadStatus.LUA_OK)
            {
                Fatal(lua.ToString(-1));
            }
            var cl = ((LuaState)lua).Top.V.ClLValue();

            return(cl.Proto);
        }
Exemplo n.º 17
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();
    }
Exemplo n.º 18
0
    private bool Load()
    {
        string LuaFile = "config.lua";

        Lua = LuaAPI.NewState();
        Lua.L_OpenLibs();
        ThreadStatus status = Lua.L_DoFile(LuaFile);

        if (status != ThreadStatus.LUA_OK)
        {
            Debug.LogError("Load Lua File Error!");
            return(false);
        }
        if (!Lua.IsTable(-1))
        {
            Debug.LogError("Load Lua File Error!");
            return(false);
        }
        this.CacheToGlobalConfig();
        return(true);
    }
Exemplo n.º 19
0
 public LuaHolder()
 {
     mLuaState = LuaAPI.NewState();
     mLuaState.L_OpenLibs();
 }
Exemplo n.º 20
0
 public static ILuaState luaL_newstate()
 {
     return(LuaAPI.NewState());
 }
Exemplo n.º 21
0
 private LuaMgr()
 {
     m_luaState = LuaAPI.NewState();
     m_luaState.L_OpenLibs();
 }