Example #1
0
        public void Initialize()
        {
            Default            = new LuaEnv();
            LuaClassCache      = new LuaClassCache();
            m_newClassCallback = OnLuaNewClass;
#if UNITY_EDITOR
            Default.AddLoader((ref string filename) => LoadFile(ref filename, ".lua"));
#else
            Default.AddLoader((ref string filename) => LoadFile(ref filename, ".lua"));
#endif

            var setupNewCallback = LoadFileAtPath("base.class")[0] as LuaFunction;
            setupNewCallback.Action(m_newClassCallback);
            OnVMCreated?.Invoke();

            var ret = LoadFileAtPath("PreRequest")[0] as LuaTable;
            OnInit    = ret.Get <LuaFunction>("init");
            OnDestroy = ret.Get <LuaFunction>("shutdown");

            OnPreRequestLoaded?.Invoke();
#if UNITY_EDITOR
            if (reportLeakMark)
            {
                leakData = Default.StartMemoryLeakCheck();
            }
#endif
            AssetService.Get().AddAfterDestroy(this);

            DestroyedTableMeta = Global.Get <LuaTable>("DestroyedTableMeta");
        }
Example #2
0
        private LuaEvnBase()
        {
            m_luaEnv = new LuaEnv();
            m_luaEnv.AddBuildin("protobuf.c", XLua.LuaDLL.Lua.LoadProtobufC);
#if UNITY_EDITOR
            m_luaEnv.AddLoader((ref string filepath) => {
                filepath = Application.dataPath + "/Lua/" + filepath.Replace('.', '/') + ".lua";
                if (File.Exists(filepath))
                {
                    return(File.ReadAllBytes(filepath));
                }
                else
                {
                    return(null);
                }
            });
#else
            m_luaEnv.AddLoader((ref string filepath) => {
                filepath       = "Lua/" + filepath.Replace('.', '/') + ".lua";
                TextAsset file = (TextAsset)Resources.Load(filepath);
                if (file != null)
                {
                    return(file.bytes);
                }
                else
                {
                    return(null);
                }
            });
#endif
            m_luaEnv.DoString(Utility.LoadLuaFile("init"));
        }
Example #3
0
        private void InitLoader()
        {
#if UNITY_EDITOR
            LuaEnv.AddLoader((ref string filename) =>
            {
                var path = string.Format("{0}/AssetBundles/ScriptsLua/{1}.lua", Application.dataPath, filename);
                if (File.Exists(path))
                {
                    var script = File.ReadAllText(path);
                    return(Encoding.UTF8.GetBytes(script));
                }
                return(null);
            });
#else
            LuaEnv.AddLoader((ref string fileName) =>
            {
                string tempName = fileName;
                string path     = "lua.lijv";
                if (fileName.Contains("/"))
                {
                    int index = fileName.LastIndexOf('/');
                    fileName  = fileName.Substring(index + 1, fileName.Length - index - 1);

                    index    = tempName.LastIndexOf('/');
                    tempName = tempName.Substring(0, index);
                    path     = "lua/" + tempName + ".lijv";
                }


                string script = io.res.LoadLuaFile(path, fileName + ".lua");
                return(Encoding.UTF8.GetBytes(script));
            });
#endif
        }
Example #4
0
        public IEnumerator StartUp()
        {
            yield return(LoadLuaAssetbundle(FilePath.DataPath + "Data/lua.unity3d"));

            //根据是否开启自动更新来设置加载方式
            if (LuaMVCConfig.AutomaticUpdateLuaScriptsFromServer)
            {
                luaEnv.AddLoader(LuaAssetLoader);
            }
            else
            {
                luaEnv.AddLoader(Loader);
            }
            this.scriptEnv = luaEnv.NewTable();
            LuaTable meta = luaEnv.NewTable();

            meta.Set("__index", luaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();
            scriptEnv.Set("self", this);
            luaEnv.DoString(LoadLua("LuaFacade"), "LuaFacade", scriptEnv);
            Action awake = scriptEnv.Get <Action>("awake");

            ondestroy = scriptEnv.Get <Action>("ondestroy");
            Debug.Log("LuaApplicationFacade:StartUp");

            if (null != awake)
            {
                awake();
                Debug.Log("LuaFacade.awake()");
            }
        }
Example #5
0
 public void PreLoaderLua()
 {
     if (LuaCallCSharpMacro.UNITY_EDITOR() == false)//只要不是deitor环境,都需要解压luadata
     {
         //先检查是否有下载的unpack lua,优先找下载的unpackdata
         string unPackluaDataFilePath = Path.Combine(PathManager.GetRootDataPath, PathManager.download_unpackLuaName);
         if (FileManager.FileExist(unPackluaDataFilePath))
         {
             YQPackageManagerEX.Instance.LoadLuaData(unPackluaDataFilePath);
         }
         else
         {
             string path = Path.Combine(PathManager.unpackPath, PathManager.unpackLuaName);
             YQPackageManagerEX.Instance.LoadLuaDataFromResource(FileManager.RemoveFileExtension(path));
         }
     }
     if (luaEnv != null)
     {
         luaEnv.AddLoader(PreLoaderLua);
         LoadScript(preLoadMainLua);
     }
     else
     {
         UnityEngine.Debug.LogError("PreLoaderLua null!!!");
     }
 }
Example #6
0
 public void Init()
 {
     //唯一的解析器
     luaEnv = new LuaEnv();
     //添加重定向委托函数
     luaEnv.AddLoader(MyCustomLoader);
     luaEnv.AddLoader(MyCustomLoaderFormAB);
 }
Example #7
0
        private void TestLuajit()
        {
            luaenv.AddLoader(CustomLoader);
            luaenv.DoString("require('testLuac1')");

            //OnLuajit();
            //SafeDoString(string.Format("require('{0}')", "testjit"));
        }
Example #8
0
        // Use this for initialization
        void Start()
        {
            LuaEnv luaenv = new LuaEnv();

#if UNITY_EDITOR
            luaenv.AddLoader(new SignatureLoader(PUBLIC_KEY, (ref string filepath) =>
            {
                Debug.Log("filepath start ; " + filepath);

                filepath = Application.dataPath + "/XLua/Examples/10_SignatureLoader/" + filepath.Replace('.', '/') + ".lua";
                Debug.Log("filepath end ; " + filepath);
                if (File.Exists(filepath))
                {
                    return(File.ReadAllBytes(filepath));
                }
                else
                {
                    return(null);
                }
            }));

            //LuaEnv.CustomLoader loader = new LuaEnv.CustomLoader((ref string file) =>
            //{
            //    Debug.LogError(file);
            //    file = Application.dataPath + "/XLua/Examples/10_SignatureLoader/" + file.Replace('.', '/') + ".lua";

            //    if (File.Exists(file))
            //    {
            //        return File.ReadAllBytes(file);
            //    }
            //    else
            //    {
            //        return null;
            //    }
            //});

            //luaenv.AddLoader(new SignatureLoader(PUBLIC_KEY, loader));
#else //为了让手机也能测试
            luaenv.AddLoader(new SignatureLoader(PUBLIC_KEY, (ref string filepath) =>
            {
                filepath       = filepath.Replace('.', '/') + ".lua";
                TextAsset file = (TextAsset)Resources.Load(filepath);
                if (file != null)
                {
                    return(file.bytes);
                }
                else
                {
                    return(null);
                }
            }));
#endif
            luaenv.DoString(@"
            require 'signatured1'
            require 'signatured2'
        ");
            luaenv.Dispose();
        }
Example #9
0
        private static void RestartLuaEnv()
        {
            CallLua("LuaHotfixDispose()");
            _luaEnv.Dispose();

            _luaEnv = new LuaEnv();
            _luaEnv.AddLoader(NormalLoader);
            _luaEnv.AddLoader(ResourcesLoader);
        }
Example #10
0
        public static void Init(bool assetBundleMode)
        {
            if (assetBundleMode)
            {
                luaEnv.AddLoader(ReadBytesFromAssetBundle);
            }
            else
            {
                luaEnv.AddLoader(ReadBytesFromEditor);
            }

            luaEnv.DoString("require 'Main'");
        }
Example #11
0
    public void Init()
    {
        if (luaEnv != null)
        {
            return;
        }

        luaEnv = new LuaEnv();
        //加载Lua脚本 重定向

        luaEnv.AddLoader((ref string filepath) =>
        {
            string path = Application.dataPath + "/Lua/" + filepath + ".lua";
            if (File.Exists(path))
            {
                return(File.ReadAllBytes(path));
            }
            else
            {
                Debug.LogError("文件不存在");
            }
            return(null);
        });

        //加载AB包的Lua脚本 重定向
        luaEnv.AddLoader((ref string filepath) =>
        {
            //Debug.Log("进入AB包重定向加载");
            ////从AB包中加载lua文件
            ////加载AB包
            //string path = Application.streamingAssetsPath + "/lua";
            //AssetBundle assetBundle = AssetBundle.LoadFromFile(path);

            ////加载Lua文件 返回 filepath + ".lua"是文件名
            //TextAsset tx = assetBundle.LoadAsset<TextAsset>(filepath + ".lua");
            ////加载lua文件 byte数组
            //return tx.bytes;
            //=====================================================================
            //通过AB包管理器加载的Lua脚本资源
            TextAsset lua = ABManager.GetInstance().LoadRes <TextAsset>("lua", filepath + ".lua");
            if (lua != null)
            {
                return(lua.bytes);
            }
            else
            {
                Debug.LogError("重定向失败,文件名为:" + filepath);
            }
            return(null);
        });
    }
Example #12
0
        private void InitCustomLoader()
        {
            m_luaEnv.AddLoader((ref string fileName) =>
            {
                string assetName = AssetUtility.GetLuaAsset(fileName);
                string data      = string.Empty;

                if (GameEntry.Base.EditorResourceMode)
                {
                    data = GameEntry.Resource.LoadTextAsset(assetName);
                }
                else
                {
                    TextAsset asset = GameEntry.Resource.LoadAssetSync(assetName) as TextAsset;
                    if (asset == null)
                    {
                        Log.Error("Lua script file is empty. file:{0}", assetName);
                        return(null);
                    }
                    data = asset.text;
                }

                if (string.IsNullOrEmpty(data))
                {
                    Log.Error("File content is null. file:{0}", assetName);
                    return(null);
                }

                return(System.Text.Encoding.UTF8.GetBytes(data));
            });
        }
Example #13
0
 void Awake()
 {
     luaEnv.AddLoader((ref string filepath) =>
     {
         return(GetLuaText(filepath));
     });
 }
Example #14
0
        //运行时和编辑时获取的方式不一样,运行时直接从实例中取即可,编辑时需要起一个虚拟机来加载序列化信息。
        private List <SerializedInfo> GetInfoList()
        {
            List <SerializedInfo> infoList = new List <SerializedInfo>();
            LuaEnv   luaEnv   = null;
            LuaTable luaClass = null;
            LuaTable defineTable;

            if (!Application.isPlaying)
            {
                luaEnv = new LuaEnv();
                luaEnv.AddLoader(LuaEngine.GetInstance().BaseLoader);
                luaEnv.DoString("ExecuteInEditorScript = true");
                var rets = luaEnv.DoString($"return require \"{m_LuaScriptPath.stringValue}\"");
                luaClass = (LuaTable)rets[0];
            }
            else
            {
                var rets = LuaEngine.GetInstance().LuaEnv.DoString($"return require \"{m_LuaScriptPath.stringValue}\"");
                luaClass = (LuaTable)rets[0];
            }
            luaClass.Get("_DefineList", out defineTable);
            defineTable.ForEach <int, LuaTable>((index, infoTable) =>
            {
                SerializedInfo info = new SerializedInfo();
                infoTable.Get("name", out info.ValueName);
                infoTable.Get("type", out info.ValueType);
                infoList.Add(info);
            });
            if (!Application.isPlaying)
            {
                luaEnv.Dispose();
            }
            return(infoList);
        }
    /// <summary>
    /// OnAfterConstructor
    /// </summary>
    protected override void OnAfterConstructor()
    {
        List <XLS_Config_Table_XLuaMap> src = StrayFogConfigHelper.Select <XLS_Config_Table_XLuaMap>();

        foreach (XLS_Config_Table_XLuaMap r in src)
        {
            if (!mXLuaConfigMaping.ContainsKey(r.id))
            {
                mXLuaConfigMaping.Add(r.id, r);
            }
        }

        xLuaEnv = new LuaEnv();
        xLuaEnv.AddLoader((ref string filepath) =>
        {
            int xLuaId        = 0;
            string xLuaString = string.Empty;
            byte[] result     = null;
            if (!int.TryParse(filepath, out xLuaId))
            {
                xLuaId = filepath.UniqueHashCode();
            }
            xLuaString = OnGetXLuaScript(xLuaId);
            if (!string.IsNullOrEmpty(xLuaString))
            {
                result = System.Text.Encoding.UTF8.GetBytes(xLuaString);
            }
            return(result);
        });
        base.OnAfterConstructor();
    }
Example #16
0
 public static void AddLoader(string luaFileName)
 {
     luaenv.AddLoader((ref string filename) =>
     {
         filename = Application.dataPath + "/LuaProject/" + filename.Replace('.', '/') + ".lua";
         if (File.Exists(filename))
         {
             return(File.ReadAllBytes(filename));
         }
         else
         {
             return(null);
         }
     });
     luaenv.DoString(string.Format("require('{0}')", luaFileName));
 }
Example #17
0
    public void TestEncryptionScript()
    {
        LuaTable         scriptEnv         = _luaEnv.NewTable();
        EncryptionHelper _encryptionHelper = new EncryptionHelper();

        //TODO: use EncryptionHelper to load encrypted lua script
        ///use loader to decrypt script

        //Decrypt nonce = 102 //2019 - 09 - 30 update
        #region YourScript
        //TODO: loader here

        _luaEnv.AddLoader(( ref string filepath ) =>
        {
            var text = Resources.Load <TextAsset>(filepath).text;
            var encryptedByteArray = Convert.FromBase64String(text);
            var decryptedByteArray = _encryptionHelper.Decrypt(encryptedByteArray, (long)102);
            // var decryptedString = Encoding.UTF8.GetString( decryptedByteArray );

            return(decryptedByteArray);
        });

        _luaEnv.DoString("require 'Encrypted.lua'");
        _luaEnv.customLoaders.Clear();

        #endregion

        GetList unknowFunc = _luaEnv.Global.GetInPath <GetList>("_unknownFunc.unknownFunc");
        if (6 - unknowFunc().Count != 0)
        {
            throw new Exception("Length not valid");
        }

        testList = new List <int>(unknowFunc());
    }
Example #18
0
 //---------------------------------------------------------------------
 public CasinosLua()
 {
     MapLuaFiles    = new Dictionary <string, byte[]>();
     MapLuaFilePath = new Dictionary <string, string>();
     LuaEnv         = new LuaEnv();
     LuaEnv.AddLoader(LuaLoaderCustom);
 }
Example #19
0
    public void Init()
    {
        luaEnv.DoString(LuaManager.GetRequireString("LuaSetting"), "LuaSetting");

        //沙盒是不传递到require的文件的,不适用lua使用self
        luaEnv.AddLoader((ref string filepath) =>
        {
            GLog.Log("LuaLoader > " + filepath);
            byte[] buffer = LuaLoader(filepath);
            if (buffer == null || buffer.Length == 0)
            {
                return(null);
            }
            else
            {
#if UNITY_EDITOR
                if (AssetManager.bundleLoadMode)
                {
                    EncryptUtil.Decryption(buffer);
                }
#else
                EncryptUtil.Decryption(buffer);
#endif
                return(buffer);
            }
        });

        GameEvent.SendEvent(GameEventType.LuaManagerReady);
    }
Example #20
0
        void Start()
        {
            LuaEnv luaenv = new LuaEnv();

            luaenv.AddLoader(MyLoader); //加载搜索lua文件的路径
            luaenv.Dispose();
        }
Example #21
0
        private void DoInit()
        {
            Env = new LuaEnv();
            ScriptLoader scriptLoader;

#if UNITY_EDITOR
            scriptLoader = new FileScriptLoader();
#else
#endif
            Env.AddLoader(scriptLoader.LoadScript);

#if DEBUG
            Global.Set("isDebug", true);
#endif
            Env.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
            Global.Set("isUsingRapidjson", true);

            Env.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);

            OOPTable         = RequireAndGetLocalTable(LUA_OOP_PATH);
            usingFunc        = OOPTable.Get <Func <string, LuaTable> >("using");
            instanceFunc     = OOPTable.Get <Func <string, LuaTable> >("instance");
            instanceWithFunc = OOPTable.Get <LuaFunction>("instancewith");

            Require(LUA_INIT_PATH);
            GameTable        = Global.Get <LuaTable>(LUA_GLOBAL_NAME);
            updateAction     = GameTable.Get <Action <float, float> >(LuaUtility.UPDATE_FUNCTION_NAME);
            lateUpdateAction = GameTable.Get <Action>(LuaUtility.LATEUPDATE_FUNCTION_NAME);

            Action initAction = GameTable.Get <Action>(LuaUtility.INIT_FUNCTION_NAME);
            initAction?.Invoke();
        }
Example #22
0
    public void InitLuaEnv()
    {
        // XLua.LuaEnv.AddIniter(XLua.CSObjectWrap.XLua_Gen_Manual_Register__.Init);
        luaEnv = new LuaEnv();
        if (luaEnv != null)
        {
            luaEnv.AddLoader(CustomLoader);

            InitExternal();
            LoadScript("BaseRequire");

            luaUpdate      = luaEnv.Global.Get <Action <float, float> >("Update");
            luaLateUpdate  = luaEnv.Global.Get <Action>("LateUpdate");
            luaFixedUpdate = luaEnv.Global.Get <Action <float> >("FixedUpdate");

            if (NetworkManager.GetInstance())
            {
                SafeDoString("require 'NetDispatcher'");
                NetworkManager.GetInstance().OnConnectCallBack     += luaEnv.Global.Get <Action <byte[]> >("OnConnectServer");
                NetworkManager.GetInstance().OnDisConnectCallBack  += luaEnv.Global.Get <Action <byte[]> >("OnDisConnectFromServer");
                NetworkManager.GetInstance().OnReceiveLineCallBack += luaEnv.Global.Get <Action <byte[]> >("OnReceiveLineFromServer");
                NetworkManager.GetInstance().OnReceiveMsgCallBack  += luaEnv.Global.Get <Action <byte[]> >("OnReceiveMsgFromServer");
            }
            else
            {
                Debug.LogError("must init network manager before init xlua manager!");
            }
        }
        else
        {
            Debug.LogError("InitLuaEnv failed!");
        }
    }
Example #23
0
        public void Init()
        {
            luaEnv = new LuaEnv();
            luaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
            luaEnv.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg);
            luaEnv.AddBuildin("protobuf.c", XLua.LuaDLL.Lua.LoadProtobufC);
#if UNITY_EDITOR
            luaEnv.AddLoader(LoadInLuaDir);
            luaEnv.DoString("print('Load in Dir')");
#else
            luaZip.LoadMain();
            luaEnv.AddLoader(luaZip.Load);
            luaEnv.DoString("print('Load in zip')");
#endif
            luaEnv.AddLoader(LoadLuaData);
        }
Example #24
0
    public void TestEncryptionScript()
    {
        LuaTable         scriptEnv         = _luaEnv.NewTable();
        EncryptionHelper _encryptionHelper = new EncryptionHelper();

        //TODO: use EncryptionHelper to load encrypted lua script
        ///use loader to decrypt script

        //Decrypt nonce = 102 //2019 - 09 - 30 update
        #region YourScript
        //TODO: loader here

        _luaEnv.AddLoader(
            (ref string filepath) =>
        {
            string text      = ((TextAsset)Resources.Load(filepath + ".lua")).text;
            byte[] decrypted = _encryptionHelper.Decrypt(Convert.FromBase64String(text), 102);
            return(decrypted);
        }
            );
        _luaEnv.DoString("require 'Encrypted'");
        _luaEnv.customLoaders.Clear();

        #endregion

        GetList unknowFunc = _luaEnv.Global.GetInPath <GetList>("_unknownFunc.unknownFunc");
        if (6 - unknowFunc().Count != 0)
        {
            throw new Exception("Length not valid");
        }

        testList = new List <int>(unknowFunc());
    }
Example #25
0
    public void Init()
    {
#if XLua
        LuaResLoader.Instance.Init(() =>
        {
            Debug.Log("ScriptManager Init");
            myLuaEnv = new LuaEnv();
            myLuaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
            myLuaEnv.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg);
            myLuaEnv.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);
            myLuaEnv.AddBuildin("ffi", XLua.LuaDLL.Lua.LoadFFI);
            //myLuaEnv.AddBuildin("BigNumber", XLua.LuaDLL.Lua.LoadBigNumber);
            //myLuaEnv.AddBuildin("sproto.core", XLua.LuaDLL.Lua.LoadSproto);

            myLuaEnv.AddLoader((ref string filename) =>
            {
                if (filename == "InMemory")
                {
                    return(System.Text.Encoding.UTF8.GetBytes("return {ccc = 9999}"));
                }
                return(System.Text.Encoding.UTF8.GetBytes(LuaResLoader.Instance.ReadFile(filename)));
            });

#if LUA_DEBUG && UNITY_EDITOR
            DoFile("RemoteDebug");
#endif

            DoFile("Main");
        });
#endif
    }
Example #26
0
 void Awake()
 {
     Instance = this;
     LuaEnv.AddLoader((ref string filepath) => {
         return(this.LoadBytes(filepath));
     });
 }
    void Start()
    {
        LuaEnv env = new LuaEnv();

        env.AddLoader(MyLoader);
        env.DoString("require 'downloadfile'");
    }
Example #28
0
 void Start()
 {
     luaDirPath = Application.dataPath + "/XLuaExamples/";
     luaEnv     = new LuaEnv();
     luaEnv.AddLoader(LoadFromFile); // AddLoader(CustomLoader)文档上有说明,自己读取lua源码以byte[]形式返回即可。
     luaEnv.DoString("require('" + fileName + "')");
 }
Example #29
0
 void Start()
 {
     luaenv = new LuaEnv();
     luaenv.AddLoader((ref string filename) =>
     {
         string path = Application.dataPath + "/../../XClientLua/lua/" + filename + ".lua";
         if (File.Exists(path))
         {
             return(File.ReadAllBytes(path));
         }
         else
         {
             path = Application.dataPath + "/../../XCommon/lua/" + filename + ".lua";
             if (File.Exists(path))
             {
                 return(File.ReadAllBytes(path));
             }
             else
             {
                 return(null);
             }
         }
     });
     luaenv.DoString("require('main/startup')");
     BTDebug.Init(luaenv);
 }
Example #30
0
    void InitLuaEnv()
    {
        luaEnv = new LuaEnv();
        if (luaEnv != null)
        {
            luaEnv.AddLoader(CustomLoader);

            InitExternal();
            SafeDoString("require('BaseRequire')");

            luaUpdate      = luaEnv.Global.Get <Action <float, float> >("Update");
            luaLateUpdate  = luaEnv.Global.Get <Action>("LateUpdate");
            luaFixedUpdate = luaEnv.Global.Get <Action <float> >("FixedUpdate");

            if (NetworkManager.GetInstance())
            {
                SafeDoString("require 'Logic.NetDispatcher'");
                NetworkManager.GetInstance().OnConnectCallBack     = luaEnv.Global.Get <Action <byte[]> >("OnConnectServer");
                NetworkManager.GetInstance().OnDisConnectCallBack  = luaEnv.Global.Get <Action <byte[]> >("OnDisConnectFromServer");
                NetworkManager.GetInstance().OnReceiveLineCallBack = luaEnv.Global.Get <Action <byte[]> >("OnReceiveLineFromServer");
                NetworkManager.GetInstance().OnReceiveMsgCallBack  = luaEnv.Global.Get <Action <byte[]> >("OnReceiveMsgFromServer");
            }
            else
            {
                Debug.LogError("must init network manager before init xlua manager!");
            }

            LoadScript("Main");
            SafeDoString("Main()");
        }
        else
        {
            Debug.LogError("InitLuaEnv failed!");
        }
    }
Example #31
0
 // Use this for initialization
 void Start()
 {
     luaenv = new LuaEnv();
     luaenv.AddLoader((ref string filename) => {
          if (filename == "InMemory")
          {
              string script = "return {ccc = 9999}";
              return System.Text.Encoding.UTF8.GetBytes(script);
          }
          return null;
      });
     luaenv.DoString("print('InMemory.ccc=', require('InMemory').ccc)");
 }