initial commit

This commit is contained in:
Valerie Wolfe 2024-03-28 21:42:10 -04:00
commit cba906b9b8
5 changed files with 73 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/obj/
/bin/

16
Program.cs Normal file
View file

@ -0,0 +1,16 @@
using System;
namespace Dungeoneer {
public sealed class Program {
public static void Main() {
Console.WriteLine("Starting");
Dungeoneer.Scripting.Run("test.py");
}
}
}

27
Scripting.cs Normal file
View file

@ -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<int, int>((sides) => { return Dungeoneer.Util.Roll(sides); });
}
public static void Run(string file) {
Engine.ExecuteFile(file, Scope);
}
}
}

14
Util.cs Normal file
View file

@ -0,0 +1,14 @@
using System.Security.Cryptography;
namespace Dungeoneer {
public static class Util {
public static int Roll(int sides) {
return RandomNumberGenerator.GetInt32(sides);
}
}
}

14
dungeoneer.csproj Normal file
View file

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ironpython" Version="3.4.1" />
</ItemGroup>
</Project>