How could I embedded socket in Lua internally, just like oslib, debuglib?

落爺英雄遲暮 提交于 2019-12-05 17:57:06

you need put luasocket stuff into the package.preload table, in this way:

lua_getfield(L, LUA_GLOBALSINDEX, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, luaopen_socket_core);
lua_setfield(L, -2, "socket.core");

// add mime.core yourself...

luasocket is a mixed C/lua module, you need to bundle both versions into your application if you want it to work without any extra files.

socket.lua loads socket.core (from socket/core.dll)
mime.lua loads mime.core (from mime/core.dll)

So in order for your application to work you will need to build all the .dll files and the .lua files into your application and manually load them (or set them up to be loaded correctly via custom package loaders).

The email you quoted is tweaking the package.preload table (in a way that appears a tad odd now but might work anyway) to get the built-in C code to be loaded correctly when require is called.

Try running

for k, v in pairs(socket) do print(k, v) end

and maybe we'll be able to help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!