I managed to install luasocket and works fine using lua5.3 but i can't find the way to install them to require from luajit.
If i write print(_VERSION) it shows luajit use lua5.1.
This is the stuff i been trying:
luarocks install luasocket
luarocks --local install luasocket
luarocks --lua-version 5.1 install luasocket
luarocks --lua-version 5.1 --local install luasocket
luarocks config lua_version 5.1
luarocks install luasocket
sock = require("/data/data/com.termux/files/home/.luarocks/lib/luarocks/rocks-5.1/socket")
package.path = package.path .. ";/data/data/com.termux/files/home/.luarocks/lib/luarocks/rocks-5.1" require "socket"
package.path = package.path .. ";/data/data/com.termux/files/home/.luarocks/lib/lua/5.1" require "socket"
...
The error:
$ luajit
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/
JIT: ON ARMv7 VFPv3 fold cse dce fwd dse narrow loop abc sink fuse
> sock = require("socket")
stdin:1: module 'socket' not found:
no field package.preload['socket']
no file './socket.lua'
no file '/data/data/com.termux/files/usr/share/luajit-2.1.0-beta3/socket.lua'
no file '/usr/local/share/lua/5.1/socket.lua'
no file '/usr/local/share/lua/5.1/socket/init.lua'
no file '/data/data/com.termux/files/usr/share/lua/5.1/socket.lua'
no file '/data/data/com.termux/files/usr/share/lua/5.1/socket/init.lua'
no file './socket.so'
no file '/usr/local/lib/lua/5.1/socket.so'
no file '/data/data/com.termux/files/usr/lib/lua/5.1/socket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
stdin:1: in main chunk
[C]: at 0xaba4406d
I tryied to move the installed files to some of those paths but still don't work.
is the proper way to install it.
That should also tell you in the last line of output where it installed the module, so you can check if that's in your
package.path.It seems you just misunderstand how
package.pathworks. From the manual:What that means is that a path like
/usr/share/lua/5.1won't find anything, because it doesn't find a valid Lua file at that path and since there's no?, no substitution is done whatsoever. The first of the two paths is OK, but many Lua modules use a file calledinit.luainstead, so for every<path>/?.luayou should always also add a<path>/?/init.luato cover that option as well.Normally Luarocks should install the packages main Lua file at
/usr/local/share/lua/5.1/socket.lua, but for your case that doesn't seem to work. You can have a look at that directory and see if the file is there at all, and check thatluarocks config deploy_lua_diractually returns/usr/local/share/lua/5.1.