mirror of
https://github.com/realXtend/OpensimPython.git
synced 2026-08-14 01:07:51 +00:00
initial commit of a loader for region modules written in python
This commit is contained in:
@@ -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<string> 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
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<Project name="PythonRegionmoduleLoader" path="addon-modules/PythonRegionmoduleLoader/Modules" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
||||
<ReferencePath>../../../bin/</ReferencePath>
|
||||
<Reference name="System"/>
|
||||
<Reference name="System.Xml"/>
|
||||
<Reference name="log4net"/>
|
||||
<Reference name="Mono.Addins"/>
|
||||
<Reference name="Nini.dll" />
|
||||
<Reference name="IronPython.dll" localCopy="true"/>
|
||||
<Reference name="IronPython.Modules.dll" localCopy="true"/>
|
||||
<Reference name="Microsoft.Scripting.dll" localCopy="true"/>
|
||||
<Reference name="Microsoft.Scripting.Core.dll" localCopy="true"/>
|
||||
<Reference name="Microsoft.Scripting.ExtensionAttribute.dll" localCopy="true"/>
|
||||
<Reference name="OpenSim.Data"/>
|
||||
<Reference name="OpenSim.Framework"/>
|
||||
<Reference name="OpenSim.Framework.Capabilities"/>
|
||||
<Reference name="OpenSim.Framework.Communications"/>
|
||||
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||
<Reference name="OpenSim.Region.Framework"/>
|
||||
<Reference name="OpenSim.Server.Base"/>
|
||||
<Reference name="OpenSim.Server.Handlers"/>
|
||||
<Reference name="OpenSim.Services.Interfaces"/>
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
<Reference name="OpenMetaverse.StructuredData"/>
|
||||
<Reference name="OpenMetaverse.Http"/>
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.cs" recurse="true"/>
|
||||
</Files>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user