dev: 更新代码,并准备LuaMod

This commit is contained in:
ZZY
2025-06-14 14:38:28 +08:00
parent 3fa39fc71e
commit 13450ea09a
20 changed files with 486 additions and 397 deletions

View File

@ -1,19 +1,19 @@
using System;
using System.IO;
using System.Linq;
using Godot;
using NLua;
class LuaMod : IDisposable {
public class LuaModManager : IDisposable {
private readonly Lua lua = new();
private static readonly Logging.Logger logger = Logging.GetLogger("LuaMod");
public LuaMod(string path, string? package_path = null) {
public LuaModManager(string path, string? package_path = null) {
lua.LoadCLRPackage();
lua.State.Encoding = System.Text.Encoding.UTF8;
lua["package.path"] = package_path ?? Path.GetDirectoryName(path) + "/?.lua;";
lua.RegisterFunction("print", new Action<object[]>(GD.Print).Method);
// Action bar = () => { GD.Print("bar"); };
// lua.RegisterFunction("bar", bar.Target, bar.Method);
lua.RegisterFunction("print", new Action<object[]>(Godot.GD.Print).Method);
logger.Info("Loading Lua Mod: " + path);
lua.DoFile(path);
}
@ -36,5 +36,9 @@ class LuaMod : IDisposable {
lua?.Dispose();
GC.SuppressFinalize(this);
}
public static void WriteComment(Delegate @delegate) {
// TODO
}
}