我想使用通道从 lua 调用 c 函数。
int initApp(lua_State *L) {
lua_createtable(L, 0, 0);
lua_pushcfunction(L, get_appinfo);
lua_setfield(L, -2, "get_appinfo");
lua_setglobal(L, "App");
return 0;
}
local function thread1(n)
return App.get_appinfo(n)
end
function startlanes()
local lanes = require 'lanes'
package.preload['App'] = function() return App end
package.loaded['App'] = App
local app = require 'App'
print(app, app.get_appinfo) --table: 0x1234 function: 0x5678
--(1)
f = lanes.gen('*', {required = {'App'}}, thread1) --Lua Error: module 'App' not found: no field package.preload['App']...
--(2)
--f = lanes.gen('App', thread1) -- Bad library name: App
a = f(1)
sleep(1)
end
当我运行变体 (1) 时,我得到Lua Error: module 'App' not found: no field package.preload['App']...no file '/App.lua'...
. 当我运行变体 (2) 时,我得到Bad library name: App
.
如何调用App.get_appinfo()
使用lanes
?我可以将所有App
函数移动到包中,但它必须从内存加载,而不是文件系统。我嵌入了所有 lua 包。