C# 定义lua函数的ALUMLUA

C# 定义lua函数的ALUMLUA,c#,lua,aluminumlua,C#,Lua,Aluminumlua,使用AlumumLua,我有一个lua文件,其中我将函数设置为一个变量,如下所示: local Start = function() print("Inside Start!") end 在.NET中,我尝试加载此文件,但它只是挂起在parse方法上,永远不会从中返回 class Program { static void Main(string[] args) { var context = new LuaContext(); context

使用AlumumLua,我有一个lua文件,其中我将函数设置为一个变量,如下所示:

local Start = function() print("Inside Start!") end
在.NET中,我尝试加载此文件,但它只是挂起在parse方法上,永远不会从中返回

class Program
{
    static void Main(string[] args)
    {
        var context = new LuaContext();

        context.AddBasicLibrary();
        context.AddIoLibrary();

        var parser = new LuaParser(context, "test.lua");

        parser.Parse();

    }
}

知道它为什么挂起来了吗?

我还没有试过AlumiumLua,但我已经用过LuaInterface很多次了。如果希望在启动时加载函数,请包括或DoFile/DoString文件,并按如下方式运行函数:

本地启动=函数()打印(“启动”)结束

开始()

如果您试图从lua定义钩子,可以将LuaInterface与KopiLua一起使用,然后按照以下方式进行:

C#:

static List<LuaFunction> hooks = new List<LuaFunction>();

// Register this void
public void HookIt(LuaFunction func)
{
    hooks.Add(func);
}

public static void WhenEntityCreates(Entity ent)
{
    // We want to delete entity If we're returning true as first arg on lua
    // And hide it If second arg is true on lua
    foreach (var run in hooks)
    {
        var obj = run.Call(ent);
        if (obj.Length > 0)
        {
            if ((bool)obj[0] == true) ent.Remove();
            if ((bool)obj[1] == true) ent.Hide();
        }
    }
}
function enthascreated(ent)
    if ent.Name == "Chest" then
          return true, true
    elseif ent.Name == "Ninja" then
          return false, true
    end
    return false, false
end