commit cba906b9b8d372ebae1baf749bac72f0d890e6c4 Author: Valerie Date: Thu Mar 28 21:42:10 2024 -0400 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..defeaaf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/obj/ +/bin/ diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..5ec3385 --- /dev/null +++ b/Program.cs @@ -0,0 +1,16 @@ +using System; + +namespace Dungeoneer { + + public sealed class Program { + + public static void Main() { + Console.WriteLine("Starting"); + + Dungeoneer.Scripting.Run("test.py"); + } + + } + +} + diff --git a/Scripting.cs b/Scripting.cs new file mode 100644 index 0000000..ed09c06 --- /dev/null +++ b/Scripting.cs @@ -0,0 +1,27 @@ +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.Remove("open"); + Scope.roll = new Func((sides) => { return Dungeoneer.Util.Roll(sides); }); + } + + public static void Run(string file) { + Engine.ExecuteFile(file, Scope); + } + } + +} + diff --git a/Util.cs b/Util.cs new file mode 100644 index 0000000..bbd239f --- /dev/null +++ b/Util.cs @@ -0,0 +1,14 @@ +using System.Security.Cryptography; + +namespace Dungeoneer { + + public static class Util { + + public static int Roll(int sides) { + return RandomNumberGenerator.GetInt32(sides); + } + + } + +} + diff --git a/dungeoneer.csproj b/dungeoneer.csproj new file mode 100644 index 0000000..4a827c0 --- /dev/null +++ b/dungeoneer.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + +