GetFunction 返回 null。Luainterface。

我在我的C#程序中加载了这个脚本

function test()
    print ("A")
end

但是当我尝试调用它时

LuaFunction func = lua.GetFunction("test")

func.call()

我得到了func为null的问题。

我错在哪里了?

点赞
用户1008957
用户1008957

你说你已经在 C# 程序中 加载test 脚本,但这不够。你需要 执行 生成的代码块,以便将全局变量 test 赋值。

始终要提醒:

function test()
    print ("A")
end

只是以下语法糖:

test = function()
    print ("A")
end

当 Lua 加载 一些代码时,它只是将源代码编译成字节码。赋值 test = function() end 仅在运行时执行,而不是编译时执行。

2012-12-01 16:32:04