レーンを使用して 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 パッケージを埋め込みます。