How to use Lua 5.2 with luasocket 3

﹥>﹥吖頭↗ 提交于 2019-11-28 00:29:40

问题


I am trying to compile luasocket 3 that I found on GitHub with lua 5.2. Problem is, I'm not sure how to bind together Lua with luasocket. Do I need to compile luasocket as DLL and then reference if somewhere in lua code, or should I just call it from lua console?


回答1:


Try installing it using luarocks. If you don't have luarocks, install it following instructions on the site.

Then download the rockspec file(luasocket-scm-0.rockspec) from luasocket repo and run

$ luarocks install *path to the rockspec file*

If everything goes OK, you'll be able to use luasocket from Lua like this:

local socket = require "socket"
-- now you can use socket.xxx functions



回答2:


Usually you only need to reference lua include files (there are only 4 needed: luaconf.h, lua.h, lualib.h, and lauxlib.h) and library/dll (-llua52 in your case). You don't say what compiler you are using, so it's difficult to be more specific, but I have script(s) that build luasocket with lua5.2 on Windows using mingw (and using gcc on OSX/Linux). For example, to compile on Windows, you can get build-win32.sh script and run it as: bash build-win32.sh 5.2 lua luasocket. It will get all the files needed (using wget) and compile everything in deps/ folder; the resulting executable and libraries will be put in ../bin folder.

You can also get compiled libraries from the same repository.



来源:https://stackoverflow.com/questions/18653212/how-to-use-lua-5-2-with-luasocket-3

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