5

I am using mac OSX. I have Lua installed through brew and Luarocks. I have the lua sockets package installed too.

When I call local http = require("socket") from the terminal lua command line interface, the module loads fine.

However when I include local http = require("socket") in my wrk test scripts, I get errors not just for socket but for other modules too. It seems like its not using the Lua on my system.

Is there a way to install dependent modules for wrk?

package.searchpath( "socket", package.path ) returns /usr/local/share/lua/5.2/socket.lua

Here is the error for reference

scripts/get_call_setup.lua: scripts/get_call_setup.lua:1: module 'socket' not found:
    no field package.preload['socket']
    no file './socket.lua'
    no file '/Users/sak/go/src/personal/wrk/obj/share/luajit-2.0.4/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 '/Users/sak/go/src/personal/wrk/obj/share/lua/5.1/socket.lua'
    no file '/Users/sak/go/src/personal/wrk/obj/share/lua/5.1/socket/init.lua'
    no file './socket.so'
    no file '/usr/local/lib/lua/5.1/socket.so'
    no file '/Users/sak/go/src/personal/wrk/obj/lib/lua/5.1/socket.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
Running 3s test @ https://ccx-courier-stage.adobe.io
Sakib
  • 1,503
  • 4
  • 26
  • 39
  • It _is_ looking in `/usr/local`, so if you installed the package `luasocket` globally (and for 5.1 or luajit), it should see it. Can you print the result of `package.searchpath( "socket", package.path )` in your _normal_ Lua interpreter and add that to the question? – nobody May 03 '17 at 14:02
  • The output of that is `/usr/local/share/lua/5.2/socket.lua` – Sakib May 03 '17 at 18:48
  • So that means you installed luasocket for Lua 5.2, but wrk is running luajit (which is 5.1-compatible). So look for a luarocks-5.1 packet in your package manager or manually install luarocks for 5.1, then install luasocket with that (i.e. targeting 5.1), and things should work. (Alternatively, manually install luasocket, IIRC it had Makefile options to pick the Lua version.) – nobody May 03 '17 at 20:15
  • I see. I installed it using homebrew for osx. So I guess homebrew uses the latest one – Sakib May 03 '17 at 23:44
  • A quick search turned up this: https://github.com/mesca/homebrew-luarocks/ which might be the right thing for you. – nobody May 03 '17 at 23:49

1 Answers1

1

Be sure Luarocks config correctly and luarocks install destination is in your path.

In terminal, run this below code to add the installed library to your path.

eval "$(luarocks path)"

Then run your code:

lua myscript.lua

Beside that, your package is installed for lua 5.2:

package.searchpath( "socket", package.path ) returns /usr/local/share/lua/5.2/socket.lua

But you run your code with lua 5.1:

no file '/usr/local/share/lua/5.1/socket.lua'

Install socket for lua 5.1 then run your code or run your script with lua 5.2 if all library is install for lua 5.2.

lua5.2 myscript.lua
James Risner
  • 5,451
  • 11
  • 25
  • 47
JACK
  • 65
  • 6