コード例 #1
0
        public void TestMethod1()
        {
            FileSystemScriptLoader fileSystemScriptLoader = new FileSystemScriptLoader();
            bool   i      = fileSystemScriptLoader.ScriptFileExists("1/MoonSharp.Interpreter.xml");
            Script script = new Script();

            script.Options.ScriptLoader = new ScriptLoader("");

            script.DoString("require \"game\"");
        }
コード例 #2
0
        public static LuaScript LoadGlobals(LuaScript script = null)
        {
            script = script ?? new LuaScript();

            // register and load all global functions here
            ((FileSystemScriptLoader)script.Options.ScriptLoader).ModulePaths = FileSystemScriptLoader.UnpackStringPaths("./scripts/?;./scripts/?.lua");
            script.Globals["GetWorldManager"]      = (Func <WorldManager>)Server.GetWorldManager;
            script.Globals["GetStaticActor"]       = (Func <string, Actor>)Server.GetStaticActors;
            script.Globals["GetStaticActorById"]   = (Func <uint, Actor>)Server.GetStaticActors;
            script.Globals["GetWorldMaster"]       = (Func <Actor>)Server.GetWorldManager().GetActor;
            script.Globals["GetItemGamedata"]      = (Func <uint, ItemData>)Server.GetItemGamedata;
            script.Globals["GetGuildleveGamedata"] = (Func <uint, GuildleveData>)Server.GetGuildleveGamedata;
            script.Globals["GetLuaInstance"]       = (Func <LuaEngine>)LuaEngine.GetInstance;

            script.Options.DebugPrint = s => { Program.Log.Debug(s); };
            return(script);
        }
コード例 #3
0
        private static Script loadScript(string filename)
        {
            Script script = new Script();

            ((FileSystemScriptLoader)script.Options.ScriptLoader).ModulePaths = FileSystemScriptLoader.UnpackStringPaths("./scripts/?;./scripts/?.lua");
            script.Globals["getWorldManager"] = (Func <WorldManager>)Server.GetWorldManager;
            script.Globals["getStaticActor"]  = (Func <string, Actor>)Server.getStaticActors;
            script.Globals["getWorldMaster"]  = (Func <Actor>)Server.GetWorldManager().GetActor;
            script.Globals["getItemGamedata"] = (Func <uint, Item>)Server.getItemGamedata;

            try
            {
                script.DoFile(filename);
            }
            catch (SyntaxErrorException e)
            {
                Log.error(String.Format("LUAERROR: {0}.", e.DecoratedMessage));
                return(null);
            }
            return(script);
        }
コード例 #4
0
ファイル: ScriptContext.cs プロジェクト: volte/doombuilderx
        internal DynValue Require(string module)
        {
            if (Path.GetExtension(module).ToLowerInvariant() != ".lua")
            {
                module = module + ".lua";
            }

            module = CheckFilename(module, "require");

            // don't actually assign value, just do our own checking to see if it's safe
            GetActualPath(module, "require");

            module = module.Substring(0, module.Length - 4);



            if (!bInitializedRequireSandbox)
            {
                FileSystemScriptLoader loader = new FileSystemScriptLoader();

                loader.IgnoreLuaPathGlobal = true;

                loader.ModulePaths =
                    new string[] {
                    Path.Combine(Path.GetDirectoryName(scriptPath), "?.lua"),
                    Path.Combine(General.Map.FilePathName, "?.lua"),
                    Path.Combine(Path.Combine(General.Map.FilePathName, "lua"), "?.lua"),
                    Path.Combine(Path.Combine(General.SettingsPath, "lua"), "?.lua"),
                    Path.Combine(Path.Combine(General.PluginsPath, "lua"), "?.lua"),
                    Path.Combine(Path.Combine(General.AppPath, "lua"), "?.lua"),
                };

                script.Options.ScriptLoader = loader;

                bInitializedRequireSandbox = true;
            }

            return(script.RequireModule(module));
        }