commit d95d8cc207f006941ea0b56a160c39e6bb9e2ee2 Author: Toni Alatalo Date: Thu Oct 7 14:38:23 2010 +0300 initial commit of a loader for region modules written in python diff --git a/Modules/PythonModuleLoader.cs b/Modules/PythonModuleLoader.cs new file mode 100644 index 0000000..6d707e0 --- /dev/null +++ b/Modules/PythonModuleLoader.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.IO; + +using log4net; +using Nini.Config; +using OpenMetaverse; + +using OpenSim.Framework; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; + +using Microsoft.Scripting; +using Microsoft.Scripting.Hosting; +using IronPython.Hosting; +using IronPython.Runtime; + +namespace PythonModuleLoader +{ + public class PythonRegionModuleHook : IRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + Scene m_scene; + IConfigSource m_config; + + private ScriptEngine m_pyengine = null; + private ScriptScope m_pyscope = null; + + #region IRegionModule interface + + public void Initialise(Scene scene, IConfigSource config) + { + m_log.Info("[PythonModuleLoader] Initializing..."); + m_scene = scene; + m_config = config; + m_pyengine = Python.CreateEngine(); + m_pyscope = m_pyengine.CreateScope(); + ICollection paths = m_pyengine.GetSearchPaths(); + paths.Add(AppDomain.CurrentDomain.BaseDirectory); + paths.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines")); + m_pyengine.SetSearchPaths(paths); + m_log.Info("Added " + AppDomain.CurrentDomain.BaseDirectory + " to python module search path"); + } + + public void PostInitialise() + { + ScriptSource source = null; + m_pyscope.SetVariable("scene", m_scene); + m_pyscope.SetVariable("config", m_config); + source = m_pyengine.CreateScriptSourceFromString( + "try:\n" + + " import pymodloader\n" + + " pymodloader.sceneinit(scene, config)\n" + + "except Exception, e:\n" + + " import traceback\n" + + " traceback.print_exc()\n", + SourceCodeKind.Statements); + source.Execute(m_pyscope); + } + + public void Close() + { + } + + public string Name + { + get { return "Python module loader"; } + } + + public bool IsSharedModule + { + get { return false; } + } + + #endregion + + } +} diff --git a/prebuild.xml b/prebuild.xml new file mode 100644 index 0000000..f2564d2 --- /dev/null +++ b/prebuild.xml @@ -0,0 +1,40 @@ + + + + ../../../bin/ + + + + + ../../../bin/ + + + + ../../../bin/ + + + + + + + + + + + + + + + + + + + + + + + + + + +