c# - LuaInterface - RegisterFunction 对象引用

标签 c# exception luainterface

我正在尝试将 LuaInterface 集成到 C# 中,但当我尝试将 C# 函数绑定(bind)到 Lua 时,出现了 System.NullReferenceException 。我尝试编译和运行的代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LuaInterface;

namespace Hobot
{
    class Program
    {
        static void Main(string[] args)
        {
            Program program = new Program();
            Lua lua = new Lua();
            lua.RegisterFunction("puts", null, typeof(Program).GetMethod("Test"));
            lua.DoFile("test.lua");
        }

        private void Test(String text)
        {
            Console.WriteLine(text);
        }
    }
}

当我运行这段代码时,我得到一个System.NullReferenceException,其中包含附加信息:对象引用未设置到对象的实例。说它在RegisterFunction 方法。

最佳答案

RegisterFunction 的目标参数中有 null

试试这个:

lua.RegisterFunction("puts", this, typeof(Program).GetMethod("Test"));

关于c# - LuaInterface - RegisterFunction 对象引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13557672/

相关文章:

c# - import_type 尝试调用全局

c# - Paypal 快速结账 : Notes not being returned

C# 从另一个窗体(radform)调用函数

delphi - 是否存在一般 E : Exception? 未捕获的异常

python - 为什么 Python/Django 不会在 Mysql : ERROR 1205 (HY000): Lock wait timeout exceeded 上引发异常

c++ - 异常允许我们分离什么?

c# - LuaInterface - 如何限制对 .Net 类的访问?

c# - 在 C# 中将字符串转换为 us-ascii

c# - 如何将 IQueryable<T> 转换为 Expression<Func<T, bool>>?

c# - 从 C# 将对象传递给 Lua 脚本