Beispiel #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects)
                    NLua?.Dispose();
                }

                // TODO: free unmanaged resources (unmanaged objects) and override finalizer
                // TODO: set large fields to null
                _disposedValue = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Load a single script from the specified manifest.
        /// </summary>
        private void LoadSingleScript(string path, ScriptManifest manifest)
        {
            string scriptFile = Path.Combine(path, manifest.ScriptFile);

            NLua.Lua lua = new NLua.Lua();
            lua.LoadCLRPackage();
            _luaAPI.RegisterFunctions(lua);
            bool success = true;

            try
            {
                lua.DoFile(scriptFile);
                LuaFunction fnc = lua.GetFunction("on_load");
                if (fnc != null)
                {
                    object[] res = fnc.Call();
                    if (res != null && res.Length == 1)
                    {
                        success = Convert.ToBoolean(res[0]);
                    }
                }

                // Cache this script object for event callbacks if the
                // init function returns success.
                if (success)
                {
                    if (_scriptObjects.ContainsKey(scriptFile))
                    {
                        // BUGBUG: What if we have scripts that register events? We need to tell
                        // them to unregister first. Add an interface for this.
                        NLua.Lua oldScript = _scriptObjects[scriptFile];
                        oldScript.Dispose();

                        _scriptObjects.Remove(scriptFile);
                    }
                    _scriptObjects.Add(scriptFile, lua);
                }

                if (manifest.InstallToToolbar)
                {
                    ToolbarDataItem item = new ToolbarDataItem
                    {
                        type    = "button",
                        name    = "Script",
                        label   = manifest.Name,
                        tooltip = manifest.Description,
                        data    = scriptFile,
                        image   = manifest.IconFile
                    };
                    CRToolbarItemCollection.DefaultCollection.Add(item);
                }
            }
            catch (Exception e)
            {
                LogFile.WriteLine("Error loading script {0} : {1}", scriptFile, e.Message);
                success = false;
            }
            if (success)
            {
                LogFile.WriteLine("Loaded and initialised script {0}", scriptFile);
            }
            else
            {
                lua.Dispose();
            }
        }
 public void Dispose()
 {
     _lua?.Dispose();
     _lua = null;
 }
Beispiel #4
0
        /// <summary>
        /// Load a single script from the specified manifest.
        /// </summary>
        private void LoadSingleScript(string path, ScriptManifest manifest)
        {
            string scriptFile = Path.Combine(path, manifest.ScriptFile);

            NLua.Lua lua = new NLua.Lua();
            lua.LoadCLRPackage();
            _luaAPI.RegisterFunctions(lua);
            bool success = true;
            try
            {
                lua.DoFile(scriptFile);
                LuaFunction fnc = lua.GetFunction("on_load");
                if (fnc != null)
                {
                    object[] res = fnc.Call();
                    if (res != null && res.Length == 1)
                    {
                        success = Convert.ToBoolean(res[0]);
                    }
                }

                // Cache this script object for event callbacks if the
                // init function returns success.
                if (success)
                {
                    if (_scriptObjects.ContainsKey(scriptFile))
                    {
                        // BUGBUG: What if we have scripts that register events? We need to tell
                        // them to unregister first. Add an interface for this.
                        NLua.Lua oldScript = _scriptObjects[scriptFile];
                        oldScript.Dispose();

                        _scriptObjects.Remove(scriptFile);
                    }
                    _scriptObjects.Add(scriptFile, lua);
                }

                if (manifest.InstallToToolbar)
                {
                    ToolbarDataItem item = new ToolbarDataItem
                    {
                        type = "button",
                        name = "Script",
                        label = manifest.Name,
                        tooltip = manifest.Description,
                        data = scriptFile,
                        image = manifest.IconFile
                    };
                    CRToolbarItemCollection.DefaultCollection.Add(item);
                }
            }
            catch (Exception e)
            {
                LogFile.WriteLine("Error loading script {0} : {1}", scriptFile, e.Message);
                success = false;
            }
            if (success)
            {
                LogFile.WriteLine("Loaded and initialised script {0}", scriptFile);
            }
            else
            {
                lua.Dispose();
            }
        }
Beispiel #5
0
 void OnDestroy()
 {
     lua.Dispose();
     lua = null;
 }
Beispiel #6
0
 public void Dispose()
 {
     _lua?.Dispose();
 }