示例#1
0
        public static LuaFunction Compile(LuaEnv env, string templateContent)
        {
            string luaScript = ComposeCode(Scanner.Parse(templateContent));

            //System.Console.WriteLine(luaScript);
            return(env.LoadString(luaScript, "Template"));
        }
示例#2
0
        void initLua(LuaEnv env)
        {
            if (env == null)
            {
                luaEnv        = new LuaEnv();
                disposeLuaEnv = true;
            }
            else
            {
                luaEnv = env;
            }

            creator = luaEnv.LoadString <Func <ContextCreator> >(@"
                        return (require 'xuui').new
                    ", "@xuui_init.lua")();

            commandSetter = luaEnv.LoadString <Func <Action <LuaTable, string, string, object> > >(@"
                        return function(options, module_name, method_name, obj)
                            options.data[module_name] = options.data[module_name] or {}
                            options.commands = options.commands or {}
                            local func = obj[method_name]
                            options.commands[string.format('%s.%s', module_name, method_name)] = function(...)
                                func(obj, ...)
                            end
                        end
                    ", "@eventSetter.lua")();

            exportSetter = luaEnv.LoadString <Func <Action <LuaTable, string, string, object> > >(@"
                        return function(options, module_name, method_name, obj)
                            options.data[module_name] = options.data[module_name] or {}
                            options.exports[module_name] = options.exports[module_name] or {}
                            local func = obj[method_name]
                            options.exports[module_name][method_name] = function(...)
                                func(obj, ...)
                            end
                        end
                    ", "@exportSetter.lua")();
        }
 public static LuaFunction Compile(LuaEnv luaenv, string snippet)
 {
     return(luaenv.LoadString(ComposeCode(Parser.Parse(snippet)), "luatemplate"));
 }
示例#4
0
 public static LuaFunction Compile(LuaEnv luaenv, string snippet)
 {
     return luaenv.LoadString(ComposeCode(Parser.Parse(snippet)), "luatemplate");
 }
示例#5
0
        public async Task <bool> Start()
        {
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <LuaConfig>(LuaConst.ConfigPath_Resources);
            if (mConfig == null)
            {
                mStartException = new XException("[TinaX.ILRuntime] Connot found config file.");;
                return(false);
            }
            if (!mConfig.EnableLua)
            {
                return(true);
            }

            mInternal_Lua_Folder_Load_Path = mConfig.FrameworkInternalLuaFolderLoadPath;
            if (!mInternal_Lua_Folder_Load_Path.IsNullOrEmpty())
            {
                if (mInternal_Lua_Folder_Load_Path.EndsWith("/"))
                {
                    mInternal_Lua_Folder_Load_Path = mInternal_Lua_Folder_Load_Path.Substring(0, mInternal_Lua_Folder_Load_Path.Length - 1);
                }
                mInternal_Lua_Folder_Load_Path_withSlash = mInternal_Lua_Folder_Load_Path + "/";
            }
            mLuaExtension = mConfig.LuaFileExtensionName;
            if (!mLuaExtension.StartsWith("."))
            {
                mLuaExtension = "." + mLuaExtension;
            }

            if (!XCore.MainInstance.TryGetBuiltinService(out Assets))
            {
                mStartException = new XException("[TinaX.ILRuntime]" + (IsChinese? "没有任何服务实现了Framework中的内置的资产加载接口": "No service implements the built-in asset loading interface in Framework"));
                return(false);
            }

            mLoader = LoadLuaFiles;
            mLuaVM.AddLoader(mLoader);

            try
            {
                await InitInternalEntry();
            }
            catch (XException e)
            {
                mStartException = e;
                return(false);
            }

            //准备好入口文件
            if (!mConfig.EntryLuaFileLoadPath.IsNullOrEmpty())
            {
                try
                {
                    TextAsset entry_ta = await Assets.LoadAsync <TextAsset>(mConfig.EntryLuaFileLoadPath);

                    mEntryFunc = mLuaVM.LoadString <LuaFunction>(entry_ta.bytes, mConfig.EntryLuaFileLoadPath);
                    Assets.Release(entry_ta);
                }
                catch (XException e)
                {
                    mStartException = e;
                    return(false);
                }
            }

            if (mUpdateTicket != null)
            {
                mUpdateTicket.Unregister();
            }
            mUpdateTicket = TimeMachine.RegisterUpdate(OnUpdate);

            await Task.Yield();

            mInited = true;
            return(true);
        }