Exemplo n.º 1
0
        // second step
        public virtual void StartScript()
        {
            _luaenv = new XLua.LuaEnv();
            _luaenv.AddBuildin("cjson", Maria.Lua.BuildInInit.LoadCJson);
            _luaenv.AddBuildin("lpeg", Maria.Lua.BuildInInit.LoadLpeg);
            _luaenv.AddBuildin("sproto.core", Maria.Lua.BuildInInit.LoadSprotoCore);
            _luaenv.AddBuildin("ball", Maria.Lua.BuildInInit.LoadBall);
            _luaenv.AddLoader((ref string filepath) => {
                UnityEngine.Debug.LogFormat("LUA custom loader {0}", filepath);

                string[] xpaths = filepath.Split(new char[] { '.' });
                string path     = "xlua/src";
                int idx         = 0;
                while (idx + 1 < xpaths.Length)
                {
                    path += "/";
                    path += xpaths[idx];
                    idx++;
                }

                TextAsset file = ABLoader.current.LoadAsset <TextAsset>(path, xpaths[idx] + ".lua");
                if (file != null)
                {
                    return(file.bytes);
                }
                else
                {
                    file = ABLoader.current.LoadAsset <TextAsset>(path + "/lualib", xpaths[idx] + ".lua");
                    if (file != null)
                    {
                        return(file.bytes);
                    }
                    return(null);
                }
            });
            _luaenv.DoString(@" require 'main' ");
            Main main = _luaenv.Global.Get <Main>("main");

            Bacon.Lua.ILuaPool pool = main();
            Maria.Lua.LuaPool.Instance.Cache <Bacon.Lua.ILuaPool>(pool);
        }
Exemplo n.º 2
0
    void initXLua()
    {
        Debug.Log("Init XLua");

        luaEnv         = new XLua.LuaEnv();
        XLua.Utils.Lua = luaEnv;

        luaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);

        luaEnv.AddLoader((ref string path) => {
            string realpath = path.Replace('.', '/');

            if (useAssetBundle)
            {
                if (!realpath.Contains("xlua/"))
                {
                    realpath           = ("assets/bytecode/" + realpath + ".bytes").ToLower();
                    string abName      = ResourceManager.Instance.LookupAssetBundleName(realpath);
                    AssetBundle bundle = ResourceManager.Instance.LoadAssetBundle(abName);
                    TextAsset ta       = bundle.LoadAsset <TextAsset>(realpath);
                    if (ta != null)
                    {
                        return(ta.bytes);
                    }
                }
            }
            else
            {
                realpath = XLua.LuaEnv.LuaDir + "/" + realpath + ".lua";
                if (File.Exists(realpath))
                {
                    return(File.ReadAllBytes(realpath));
                }
            }

            return(null);
        });
    }
Exemplo n.º 3
0
        static int _m_AddBuildin(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                XLua.LuaEnv gen_to_be_invoked = (XLua.LuaEnv)translator.FastGetCSObj(L, 1);



                {
                    string _name = LuaAPI.lua_tostring(L, 2);
                    XLua.LuaDLL.lua_CSFunction _initer = translator.GetDelegate <XLua.LuaDLL.lua_CSFunction>(L, 3);

                    gen_to_be_invoked.AddBuildin(_name, _initer);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemplo n.º 4
0
        public Application(Maria.Util.App app)
        {
            _app    = app;
            _tiSync = new TimeSync();
            _tiSync.LocalTime();
            _lastTi = _tiSync.LocalTime();

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            //_cotype = CoType.THREAD;
            _cotype = CoType.CO;
#elif UNITY_IOS || UNITY_ANDROID
            _cotype = CoType.CO;
#endif
            if (_cotype == CoType.THREAD)
            {
                _semaphore           = new Semaphore(1, 1);
                _worker              = new Thread(new ThreadStart(Worker));
                _worker.IsBackground = true;
                _worker.Start();
                UnityEngine.Debug.LogWarning("create thread success.");
            }
            else
            {
                UnityEngine.Debug.LogWarning("create co success.");
            }
            _luaenv = new XLua.LuaEnv();
            _luaenv.AddBuildin("cjson", XLua.LuaDLL.Lua.LoadCJson);
            _luaenv.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg);
            _luaenv.AddBuildin("sproto.core", XLua.LuaDLL.Lua.LoadSprotoCore);
            _luaenv.AddLoader((ref string filepath) => {
                UnityEngine.Debug.LogFormat("LUA custom loader {0}", filepath);

                string[] xpaths = filepath.Split(new char[] { '.' });
                string path     = "xlua/src";
                int idx         = 0;
                while (idx + 1 < xpaths.Length)
                {
                    path += "/";
                    path += xpaths[idx];
                    idx++;
                }

                TextAsset file = ABLoader.current.LoadAsset <TextAsset>(path, xpaths[idx] + ".lua");
                if (file != null)
                {
                    return(file.bytes);
                }
                else
                {
                    file = ABLoader.current.LoadAsset <TextAsset>(path + "/lualib", xpaths[idx] + ".lua");
                    if (file != null)
                    {
                        return(file.bytes);
                    }
                    return(null);
                }
            });
            _luaenv.DoString(@"
require 'main'
");
        }
Exemplo n.º 5
0
        LuaManager()
        {
            luaEnv = new LuaEnv();

            luaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
        }
Exemplo n.º 6
0
 public static void AddLib(LuaEnv env)
 {
     env.AddBuildin("core.clib.world_c", LuaDLL.Lua.cs_luaopen_core_clib_world_c);
     env.AddBuildin("core.clib.rvo2", LuaDLL.Lua.cs_luaopen_rvo2);
     env.AddBuildin("core.rapidjson", LuaDLL.Lua.cs_luaopen_rapidjson);
     env.AddBuildin("ejoy2dx.sproto.c", LuaDLL.Lua.cs_luaopen_sproto_core);
     env.AddBuildin("ejoy2dx.lpeg.c", LuaDLL.Lua.cs_luaopen_lpeg);
     env.AddBuildin("ejoy2dx.crypt.c", LuaDLL.Lua.cs_luaopen_crypt);
     env.AddBuildin("ejoy2dx.rc4.c", LuaDLL.Lua.cs_luaopen_rc4_c);
     env.AddBuildin("ejoy2dx.md5.c", LuaDLL.Lua.cs_luaopen_md5);
     env.AddBuildin("ejoy2dx.lzma.c", LuaDLL.Lua.cs_luaopen_lzma);
     env.AddBuildin("ejoy2dx.socket.c", LuaDLL.Lua.cs_luaopen_lsocket);
     env.AddBuildin("sconn_socket.c", LuaDLL.Lua.cs_luaopen_sconn_socket);
     env.AddBuildin("ejoy2dx.timesync.c", LuaDLL.Lua.cs_luaopen_timesync);
     env.AddBuildin("ejoy2dx.timer.c", LuaDLL.Lua.cs_luaopen_timer_c);
 }
Exemplo n.º 7
0
 /// <summary>
 /// 给lua虚拟机增加一些内建的组件,这样lua脚本才可以require这些组件
 /// </summary>
 /// <param name="luaenv"></param>
 public static void AddBasicBuiltin(XLua.LuaEnv luaenv)
 {
     luaenv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
     luaenv.AddBuildin("protobuf.c", XLua.LuaDLL.Lua.LoadProtobufC);
 }
Exemplo n.º 8
0
        public static void AddLib(LuaEnv env)
        {
            env.AddBuildin("socket.core", LuaDLL.Lua.cs_luaopen_socket_core);

            env.AddBuildin("socket", LuaDLL.Lua.cs_luaopen_socket_core);
        }
Exemplo n.º 9
0
 public static void LpegAddBuildin(XLua.LuaEnv luaEnv)
 {
     luaEnv.AddBuildin("lpeg", LuaDLL.Lua.LoadLpeg);
 }
Exemplo n.º 10
0
 public static void SprotoAddBuildin(XLua.LuaEnv luaEnv)
 {
     luaEnv.AddBuildin("sproto.core", LuaDLL.Lua.LoadSprotoCore);
 }
Exemplo n.º 11
0
 public static void PbAddBuildin(XLua.LuaEnv luaEnv)
 {
     luaEnv.AddBuildin("pb", LuaDLL.Lua.LoadPb);
 }
Exemplo n.º 12
0
 public static void RapidJsonAddBuildin(XLua.LuaEnv luaEnv)
 {
     luaEnv.AddBuildin("rapidjson", LuaDLL.Lua.LoadRapidJson);
 }