Luasocket installation

Question:
I’m trying to make HTTP requests in Lua, but facing an issue when installing the luasocket library.

~/Learning-Lua$ luarocks install luasocket

Error: /nix/store/1nkg0bcsjk04lh1mwsxql2rvwv6rxlh8-luarocks-3.9.1/lib/luarocks/rocks-5.1 does not exist and your user does not have write permissions in /nix/store/1nkg0bcsjk04lh1mwsxql2rvwv6rxlh8-luarocks-3.9.1 
-- you may want to run as a privileged user or use your local tree with --local.
~/Learning-Lua$ sudo luarocks install luasocket

Error: /nix/store/1nkg0bcsjk04lh1mwsxql2rvwv6rxlh8-luarocks-3.9.1/lib/luarocks/rocks-5.1 does not exist and your user does not have write permissions in /nix/store/1nkg0bcsjk04lh1mwsxql2rvwv6rxlh8-luarocks-3.9.1 
-- you may want to run as a privileged user or use your local tree with --local.

Could you try the template linked here?

Same thing.

~/luarocks-template-test$ luarocks install luasocket

Error: /nix/store/fa19596f7db4y3fhi1h92dzfxvj11w74-luarocks-3.9.1/lib/luarocks/rocks-5.3 does not exist and your user does not have write permissions in /nix/store/fa19596f7db4y3fhi1h92dzfxvj11w74-luarocks-3.9.1 
-- you may want to run as a privileged user or use your local tree with --local.

Try adding --local to the end of that command, it should work.

Weird, it says that it installed successfully but then when I run:

local http = require("socket.http")

I get the error:

lua: main.lua:1: module 'socket.http' not found:
    no field package.preload['socket.http']
    no file '/home/runner/Trying-to-make-web-requets-desperately/.luarocks/share/lua/5.3/socket/http.lua'
    no file './share/lua/5.3/socket/http.lua'
    no file './socket/http.lua'
    no file './socket/http/init.lua'
    no file '/home/runner/Trying-to-make-web-requets-desperately/.luarocks/lib/lua/5.3/socket/http.so'
    no file './lib/lua/5.3/socket/http.so'
    no file './socket/http.so'
    no file './lib/lua/5.3/loadall.so'
    no file '/home/runner/Trying-to-make-web-requets-desperately/.luarocks/lib/lua/5.3/socket.so'
    no file './lib/lua/5.3/socket.so'
    no file './socket.so'
    no file './lib/lua/5.3/loadall.so'
stack traceback:
    [C]: in function 'require'
    main.lua:1: in main chunk
    [C]: in ?

Am I doing something wrong? I’m new to Lua so that’s very possible lol

I’m… Not sure. Does just using require("socket") work by chance? Beyond that, I’ve got no clue, as I’ve never used lua.

No, still the same issue.

lua: main.lua:1: module 'socket' not found:
    no field package.preload['socket']
    no file '/home/runner/Trying-to-make-web-requets-desperately/.luarocks/share/lua/5.3/socket.lua'
    no file './share/lua/5.3/socket.lua'
    no file './socket.lua'
    no file './socket/init.lua'
    no file '/home/runner/Trying-to-make-web-requets-desperately/.luarocks/lib/lua/5.3/socket.so'
    no file './lib/lua/5.3/socket.so'
    no file './socket.so'
    no file './lib/lua/5.3/loadall.so'
stack traceback:
    [C]: in function 'require'
    main.lua:1: in main chunk
    [C]: in ?

Hm, what if you reinstall socket, but swap the --local with --tree=.luarocks? That was done at one point in the other topic.

That fixed it, thank you so much!

1 Like

I made a template before, for the topic you linked (though I know nothing about Lua):
https://replit.com/@NuclearPasta0/Lua-with-LuaRocks

I know, that’s why I linked your post with it :upside_down_face:

Whoops I skimmed the first posts too quickly.
Hmm, maybe I should rename the readme.md file that has all of the package instructions to README.md in my template…

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.