Hello!
On Thu, Sep 4, 2014 at 5:29 AM, Donatas Abraitis wrote:
> I'm trying to use require "socket", but getting an error like:
>
> 2014/09/04 08:26:57 [error] 1493#0: *1 lua entry thread aborted: runtime
> error: error loading module 'socket.core' from file
> '/usr/local/lib/lua/5.1/socket/core.so':
> /usr/local/lib/lua/5.1/socket/core.so: undefined symbol: luaL_openlib
The LuaSocket library uses the old Lua 5.0 C API luaL_openlib and your
standard Lua 5.1 interpreter build disables the Lua 5.0 compatibility
support.
To quote the related comment in lua-5.1.5's luaconf.h header file:
"/*
@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
@* behavior.
** CHANGE it to undefined as soon as you replace to 'luaL_register'
** your uses of 'luaL_openlib'
*/
"
You can either switch to LuaJIT 2 (highly recommended) or rebuild your
Lua 5.1 to enable Lua 5.0 compatibility.
BTW, the LuaSocket library always block the nginx event loop and ruin
the performance of nginx so it's strongly discouraged. (It is only
fine to use LuaSocket in the context of init_by_lua* where blocking IO
does not really matter much because in that stage nginx has not yet
started serving any requests yet.)
You should use the 100% nonblocking cosocket API provided by ngx_lua
instead, see https://github.com/openresty/lua-nginx-module#ngxsockettcp
I'm cc'ing the openresty-en mailing list. Please join the list and
post future questions there. See http://openresty.org/#Community
Thanks for your cooperation!
Best regards,
-agentzh