Loading modules in Lua

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Loading modules in Lua

Abrar Galib
I am running Lua 5.3 on OpenSuse Tumbleweed system. I am trying to use Lua as a scripting language in the context of HAProxy webserver. I have Lua installed which, doing `lua -v` at terminal shows Lua 5.3.4.

The problem I have is when I try to run a specific Lua script, auth-request.lua. The first line of code there tries to import http from socket.http:

    local http = require("socket.http")

When I attempt to start HAProxy, i get the following error:

    module socket.http is not found

I installed luasocket using luarocks and the error was not resolved.

I have tried the following since then:

1. Added the location of *.so files from /usr/lib64/lua/5.3/ by defining them as absolute paths in the LUA_PATH environment variable. I added all *.lua files from /usr/share/lua/5.3/ to LUA_CPATH. I checked if the current shell has those values declared by restarting the shell and using echo to print out the paths. This did not solve the problem.

2. After reading about lua require function and how it uses patterns for file names, I tried using /usr/lib64/lua/5.3/?.so for LUA_PATH and /usr/share/lua/5.3/?.lua for LUA_CPATH. This did not solve the problem.

3. Lastly, I added the following lines on auth-request.lua:

     package.path = "/usr/lib64/lua/5.3/?.so"
     package.cpath = "/usr/share/lua/5.3/?.lua"

This did not solve the problem either.


Some help will be greatly appreciated
Reply | Threaded
Open this post in threaded view
|

Re: Loading modules in Lua

Andrew Gierth
>>>>> "Abrar" == Abrar Galib <[hidden email]> writes:

 Abrar> 1. Added the location of *.so files from /usr/lib64/lua/5.3/ by
 Abrar> defining them as absolute paths in the LUA_PATH environment
 Abrar> variable. I added all *.lua files from /usr/share/lua/5.3/ to
 Abrar> LUA_CPATH. I checked if the current shell has those values
 Abrar> declared by restarting the shell and using echo to print out the
 Abrar> paths. This did not solve the problem.

You have these backwards - LUA_PATH is for *.lua files and LUA_CPATH for
*.so files.

What were your package.path and package.cpath set to _before_ you
started changing things?

--
Andrew.

Reply | Threaded
Open this post in threaded view
|

Re: Loading modules in Lua

Andrew Gierth
In reply to this post by Abrar Galib
>>>>> "Abrar" == Abrar Galib <[hidden email]> writes:

 Abrar> I am running Lua 5.3 on OpenSuse Tumbleweed system. I am trying
 Abrar> to use Lua as a scripting language in the context of HAProxy
 Abrar> webserver. I have Lua installed which, doing `lua -v` at
 Abrar> terminal shows Lua 5.3.4.

That doesn't actually mean that HAProxy is using that version of lua -
it may have embedded a different version. You need to check that
instead.

--
Andrew.

Reply | Threaded
Open this post in threaded view
|

Re: Loading modules in Lua

Jonathan Goble
On Fri, Mar 1, 2019, 10:59 AM Andrew Gierth <[hidden email]> wrote:
>>>>> "Abrar" == Abrar Galib <[hidden email]> writes:

 Abrar> I am running Lua 5.3 on OpenSuse Tumbleweed system. I am trying
 Abrar> to use Lua as a scripting language in the context of HAProxy
 Abrar> webserver. I have Lua installed which, doing `lua -v` at
 Abrar> terminal shows Lua 5.3.4.

That doesn't actually mean that HAProxy is using that version of lua -
it may have embedded a different version. You need to check that
instead.

Also, if HAProxy does indeed embed its own version of Lua, then luasocket would need to be installed for *that* Lua, which is separate and independent from your system Lua (the one you invoke with the "lua" command and which LuaRocks installed to). The embedded Lua might not even have an interactive interpreter or any means of installing additional packages.