Esempio n. 1
0
        private void DebugScript(string filename)
        {
            m_Script = new Script(CoreModules.Preset_Complete);
            m_Script.Options.UseLuaErrorLocations = true;
            m_Script.Options.DebugPrint           = s => { Console_WriteLine("{0}", s); };

            ((ScriptLoaderBase)m_Script.Options.ScriptLoader).ModulePaths = ScriptLoaderBase.UnpackStringPaths("Modules/?;Modules/?.lua");

            try
            {
                m_Script.LoadFile(filename, null, filename.Replace(':', '|'));
            }
            catch (Exception ex)
            {
                txtOutput.Text = "";
                Console_WriteLine("{0}", ex.Message);
                return;
            }

            m_Script.AttachDebugger(this);

            Thread m_Debugger = new Thread(DebugMain);

            m_Debugger.Name         = "MoonSharp Execution Thread";
            m_Debugger.IsBackground = true;
            m_Debugger.Start();
        }
    public static Script LoadScript2()
    {
        Script.DefaultOptions.ScriptLoader = new UnityAssetsScriptLoader("MoonSharp/Scripts/Test");
        ((ScriptLoaderBase)Script.DefaultOptions.ScriptLoader).ModulePaths =
            ScriptLoaderBase.UnpackStringPaths("MoonSharp/Scripts/Test/?;MoonSharp/Scripts/Test/?.txt");


        var _main = new Script();

        _main.DoFile("Test");
        return(_main);
    }
Esempio n. 3
0
    //---------------------------------------------------
    // 最初の更新
    //---------------------------------------------------
    void Start()
    {
        ((ScriptLoaderBase)m_Lua.Options.ScriptLoader).ModulePaths =
            ScriptLoaderBase.UnpackStringPaths(UnityAssetsScriptLoader.DEFAULT_PATH + "/?");

        m_Lua.Globals["obj"] = new MyLua(this);

        var ret = m_Lua.DoFile("main.lua");        //Script.RunFile("test");

        Debug.Log(ret.Table);
        if (ret.Table != null)
        {
            foreach (DynValue pKey in ret.Table.Keys)
            {
                Debug.Log(pKey.CastToString() + "," + ret.Table.Get(pKey));
                m_Text.text += ret.Table.Get(pKey) + "\n";
            }

            //Debug.Log(ret.Table.Values);
            //Debug.Log( m_Lua.Globals.Get("req").String );
        }

        TryLuaCoroutine();
    }
Esempio n. 4
0
 public void SetSearchPath(string paths = "./?;./?.lua")
 {
     ((ScriptLoaderBase)_script.Options.ScriptLoader).ModulePaths =
         ScriptLoaderBase.UnpackStringPaths(paths);
 }
Esempio n. 5
0
    private void LoadAutorunFiles()
    {
        string modulesPath = Path.Combine(Application.streamingAssetsPath, "modules");

        foreach (var folder in Directory.GetDirectories(modulesPath, "*.*", SearchOption.AllDirectories))
        {
            string moduleFolder  = Path.Combine(modulesPath, folder + "/lua");
            string autorunFolder = Path.Combine(moduleFolder, "autorun");
            if (Directory.Exists(autorunFolder))
            {
                foreach (var file in Directory.GetFiles(autorunFolder, "*.*", SearchOption.AllDirectories))
                {
                    if (Path.GetExtension(file) == ".lua")
                    {
                        try {
                            Script luaScript = new Script();
                            ((ScriptLoaderBase)luaScript.Options.ScriptLoader).ModulePaths = ScriptLoaderBase.UnpackStringPaths(moduleFolder + "/?;" + moduleFolder + "/?.lua");
                            AssignLuaGlobals(luaScript);
                            DynValue luaOutput = luaScript.DoFile(file);
                        } catch (InterpreterException ex) {
                            ThrowExceptionToConsole(ex);
                        }
                    }
                }
            }
        }
    }
 public HandlerCenter()
 {
     script = new Script();
     script.Globals["sendMessage"] = (Action <int, string>)MessageSend;
     ((ScriptLoaderBase)script.Options.ScriptLoader).ModulePaths = ScriptLoaderBase.UnpackStringPaths("Lua/?;Lua/?.lua");
 }
Esempio n. 7
0
 /// <summary>
 /// This will attempt to compile the referenced script at the driver side, with an
 /// optional socket object attached. This does not parse any auto-includes or auto
 /// requires.
 /// </summary>
 /// <param name="script">The string context of the script</param>
 /// <param name="channel">The TCP channel related (for informing)</param>
 public static bool ValidateRawScriptCode(string script, IChannelHandlerContext channel = null)
 {
     try
     {
         var runscript = new Script {
             Options = { ScriptLoader = new BittyScriptLoader() }
         };
         // This is also where we load all of the BFun globals
         ((BittyScriptLoader)runscript.Options.ScriptLoader).IgnoreLuaPathGlobal = true;
         ((BittyScriptLoader)runscript.Options.ScriptLoader).ModulePaths         = ScriptLoaderBase.UnpackStringPaths("/system/?.lua;/objects/?.lua;/modules/?.lua");
         DynValue res = runscript.DoString(script);
         return(true);
     }
     catch (ScriptRuntimeException e)
     {
         Log.Warning($"Script validation failed: {e.DecoratedMessage}");
         return(false);
     }
 }