コード例 #1
0
ファイル: PluginManager.cs プロジェクト: r00t-s/SharpStar
        public void LoadPlugin(string file)
        {
            if (_plugins.Any(p => p.PluginFile == file))
            {
                throw new Exception("This plugin has already been loaded!");
            }

            FileInfo fInfo = new FileInfo(file);

            if (!fInfo.Exists)
            {
                throw new FileNotFoundException("Could not find plugin file!");
            }

            if (fInfo.Extension == ".js")
            {
                IPlugin plugin = new JavaScriptPlugin(fInfo.FullName);

                plugin.OnLoad();

                lock (_pluginLocker)
                    _plugins.Add(plugin);

                Logger.Info("Loaded JavaScript plugin {0}", fInfo.Name);
            }
            else if (fInfo.Extension == ".lua")
            {
                IPlugin plugin = new LuaPlugin(fInfo.FullName);

                plugin.OnLoad();

                lock (_pluginLocker)
                    _plugins.Add(plugin);

                Logger.Info("Loaded Lua plugin {0}", fInfo.Name);
            }
            else if (fInfo.Extension == ".py")
            {
                IPlugin plugin = new PyPlugin(fInfo.FullName);

                plugin.OnLoad();

                lock (_pluginLocker)
                    _plugins.Add(plugin);

                Logger.Info("Loaded Python plugin {0}", fInfo.Name);
            }
        }
コード例 #2
0
ファイル: PyPlugin.cs プロジェクト: r00t-s/SharpStar
        public void OnLoad()
        {
            _source       = _engine.CreateScriptSourceFromFile(PluginFile);
            _compiledCode = _source.Compile();

            _compiledCode.Execute(_scope);

            _mainPythonClass = _engine.Operations.Invoke(_scope.GetVariable(MainClassName));

            try
            {
                _engine.Operations.InvokeMember(_mainPythonClass, "on_load");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Plugin {0} caused error: {1}", Path.GetFileName(PluginFile), ex.Message);
            }
        }