43 lines
948 B
C#
43 lines
948 B
C#
using System.Collections.Generic;
|
|
using IronPython.Hosting;
|
|
using Microsoft.Scripting.Hosting;
|
|
|
|
namespace Dungeoneer {
|
|
|
|
public static class Scripting {
|
|
private static ScriptEngine Engine;
|
|
public static dynamic Scope;
|
|
|
|
static Scripting() {
|
|
// set up python engine
|
|
Engine = Python.CreateEngine();
|
|
Scope = Engine.CreateScope();
|
|
dynamic builtin = Engine.GetBuiltinModule();
|
|
|
|
var paths = Engine.GetSearchPaths();
|
|
paths.Add("/usr/lib/python3.12/");
|
|
Engine.SetSearchPaths(paths);
|
|
|
|
// set up python environment
|
|
builtin.SetVariable("input", (Func<string, string>)Input);
|
|
builtin.RemoveVariable("open");
|
|
|
|
Scope.repl = Program.ReplCommands;
|
|
|
|
// helper functions
|
|
Scope.roll = (Func<int, int>)Dungeoneer.Util.Roll;
|
|
}
|
|
|
|
public static void Run(string file) {
|
|
Engine.ExecuteFile(file, Scope);
|
|
}
|
|
|
|
public static string Input(string prompt) {
|
|
Console.Write(prompt);
|
|
return Console.ReadLine();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|