在 Lua 中,通过 userdata 表访问被求值的 C 函数值

我有一段 Lua 代码,它是从一个 C 程序中调用的,该程序传递了一个表格。

该表包含一个表,该表有一个 LUA 报告为 "function" 类型的字段。

我想调用该函数并获取其返回值,但以下代码会导致崩溃(????stack corruption????):

function myFunc (tableIn)
    local interface = tableIn["interface"] -- type(interface) is table
    local targetFunc = interface["targetFunc"] -- type(targetFunc) is function
    local value = targetFunc()
    ...
end

因此,我认为我需要向 targetFunc(...) 传递一个或多个参数,但是我不知道 targetFunc() 需要什么参数,我也无法访问 targetFunc 的文档或代码,我还猜想它是用 C 编写的。

我看过了线程 lua - get the list of parameter names of a function, from outside the function 并按建议运行了代码,但返回的似乎只是 "\ * temporary"。

问题是:是否有一些 "标准" 调用从 LUA 中的 C 例程的方法,或者是否有任何其他编程方法(甚至一次性的)来查找 targetFunc(...) 需要多少个以及什么类型的参数。

即使回答是 "没有 - 你需要看一下 targetFunc(...) 的代码/文档",也会很有帮助!

感谢您的帮助!

点赞