31 lines
696 B
C#
31 lines
696 B
C#
using System.Collections.Generic;
|
|
using IronPython.Hosting;
|
|
using Microsoft.Scripting.Hosting;
|
|
|
|
namespace Dungeoneer {
|
|
|
|
public static class Scripting {
|
|
private static ScriptEngine Engine;
|
|
private static dynamic Scope;
|
|
|
|
static Scripting() {
|
|
// set up python engine
|
|
Engine = Python.CreateEngine();
|
|
Scope = Engine.CreateScope();
|
|
dynamic builtin = Engine.GetBuiltinModule();
|
|
|
|
// set up python environment
|
|
builtin.RemoveVariable("compile");
|
|
builtin.SetVariable("exec", (Action<string>)Run);
|
|
builtin.RemoveVariable("open");
|
|
|
|
Scope.roll = (Func<int, int>)Dungeoneer.Util.Roll;
|
|
}
|
|
|
|
public static void Run(string file) {
|
|
Engine.ExecuteFile(file, Scope);
|
|
}
|
|
}
|
|
|
|
}
|
|
|