LuaSocket socket/core.dll required location?

柔情痞子 提交于 2021-01-27 18:16:49

问题


When I use

local socket = require("socket.core")

It works fine, the dll is located at "dir/socket/core.dll" but when I move the dll to say

"dir/folder/core.dll" and use

local socket = require("folder.core.")

It returns that it was found however it could not find the specific module in folder.core.

How do I use Luasocket outside of it's socket.core requirements?

Thanks!


回答1:


If you want to require("socket.core"), the shared library (dll) has to have an exported function called luaopen_socket_core (which the LuaSocket library has). Thus, it always needs to be called as require("socket.core").

If you want to move the DLL into some other folder, you have to modify package.cpath, which contains the file patterns which will be checked.

Let's say that you want to move the LuaSocket binary to folder. You have to place the binary in folder/socket/core.dll and modify package.cpath prior to calling require:

package.cpath = package.cpath .. ';folder/?.dll'
local socket = require('socket.core')

? represents the name passed to require translated to file paths: . -> /, i.e. socket.core -> socket/core.




回答2:


I think you just need to remove the dot at the end.

local socket = require("folder.core")


来源:https://stackoverflow.com/questions/6244380/luasocket-socket-core-dll-required-location

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