c# - AluminiumLua定义lua函数

标签 c# lua aluminumlua

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

local Start = function() print("Inside Start!") end

在 .NET 中,我尝试加载此文件,但它只是卡在解析方法上并且永远不会从中返回。

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

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

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

        parser.Parse();

    }
}

知道它为何挂起吗?

最佳答案

我还没有尝试过AluminiumLua,但是我已经使用过LuaInterface很多次了。如果您希望函数在启动时加载,请包含或 DoFile/DoString 您的文件并运行函数,如下所示:

本地 Start = function() print("Startup") end

开始()

如果您尝试从 lua 定义钩子(Hook),您可以将 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();
        }
    }
}

lua:

function enthascreated(ent)
    if ent.Name == "Chest" then
          return true, true
    elseif ent.Name == "Ninja" then
          return false, true
    end
    return false, false
end

关于c# - AluminiumLua定义lua函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19480326/

相关文章:

c# - 在 Entity Framework 中订购包含的实体的最佳方式?

c# - Process.WaitForExit 不使用 __debugbreak 触发

javascript - Actionlink rowindex 存储到 C# get 设置

c - lua_numbertointeger - 为什么我们可以假设 INT_MIN 具有作为 float 的精确表示?

lua - 适用于 IEEE 802.15.4 的 Wireshark Lua 解析器 - DissectorTable 名称?

function - 卢阿: passing parameter to other function problem

c# - Aluminium Lua - 寄存器函数

c# - 在字符串列表中查找子字符串