【问题标题】:AluminumLua defining lua functionAluminumLua 定义 lua 函数
【发布时间】:2013-10-29 02:34:30
【问题描述】:

使用 AluminumLua 我有一个 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();

    }
}

任何想法为什么它挂起?

【问题讨论】:

    标签: c# lua aluminumlua


    【解决方案1】:

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

    local Start = function() print("Startup") end

    开始()

    如果你想从 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
    

    【讨论】:

      猜你喜欢
      • 2013-11-27
      • 2017-05-22
      • 2014-02-10
      • 1970-01-01
      • 2015-06-02
      • 2019-07-15
      • 2011-08-29
      • 2019-12-06
      • 2015-11-11
      相关资源
      最近更新 更多