luasocket 2.0.2 only supporte Lua 5.1 but not 5.2

简介:
环境Lua 5.2.3中 安装luasocket 2.0.2时遇到如下错误 : 
[root@db-172-16-3-33 luasocket-2.0.2]# make
cd src; make all
make[1]: Entering directory `/opt/soft_bak/luasocket-2.0.2/src'
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o luasocket.o luasocket.c
In file included from luasocket.c:31:
auxiliar.h:38: error: expected declaration specifiers or ‘...’ before ‘luaL_reg’
luasocket.c:50: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mod’
luasocket.c:60: warning: ISO C does not allow extra ‘;’ outside of a function
luasocket.c:62: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘func’
luasocket.c:66: warning: ISO C does not allow extra ‘;’ outside of a function
luasocket.c: In function ‘base_open’:
luasocket.c:92: warning: implicit declaration of function ‘luaL_openlib’
luasocket.c:92: error: ‘func’ undeclared (first use in this function)
luasocket.c:92: error: (Each undeclared identifier is reported only once
luasocket.c:92: error: for each function it appears in.)
luasocket.c: In function ‘luaopen_socket_core’:
luasocket.c:116: error: ‘mod’ undeclared (first use in this function)
make[1]: *** [luasocket.o] Error 1
make[1]: Leaving directory `/opt/soft_bak/luasocket-2.0.2/src'
make: *** [all] Error 2

经过查询, 发现luasocket 2.0.2只支持Lua 5.1, 原因是用到了5.1中的一个数据类型, 但是5.2里面没有.
pkulchenko commented  a year ago

In file included from luasocket.c:31:0:
auxiliar.h:38:61: error: unknown type name ‘luaL_reg’

@masterkorp, this looks like it may still be using Lua 5.2 includes. From auxiliar.h:

#include "lauxlib.h"

int auxiliar_open(lua_State *L);
void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func);

Lua 5.1 lauxlib.h includes defined for luaL_reg (line 170):

#define luaL_reg    luaL_Reg

but Lua 5.2 lauxlib.h doesn't include that, which would explain why the type is unknown.

如果一定要在5.2上使用luasocket, 可以去github下最新版本
make的时候也需要注意, 通过luasocket的makefile可以看到, 如果要支持5.2的话, 需要使用both安装.

# Targets:
#   install            install system independent support
#   install-unix           also install unix-only support
#   install-both       install for both lua5.1 and lua5.2 
#   install-both-unix      also install unix-only 
#   print                  print the build settings


简明步骤 : 
# git clone  https://github.com/diegonehab/luasocket
# cd luasocket
# make
# make install-both-unix
[root@db-172-16-3-33 luasocket]# lua
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> require ("socket")

打印socket包含的对象 : 
function print_tbl(v_s) 
  if type(v_s) == "table" then
    print(v_s, "contents:-----------------------------------------------")
    for k,v in pairs(v_s) do 
      if type(v_s[k]) == "table" 
      then 
        print(v_s,k,v)
        print_tbl(v_s[k]) 
      else 
        print(v_s,k,v) 
      end 
    end
  else
    error("please enter a table variable.")
  end
end

> s = require("socket")

> print_tbl(s)
table: 0x15b9410        contents:-----------------------------------------------
table: 0x15b9410        dns     table: 0x15b95c0
table: 0x15b95c0        contents:-----------------------------------------------
table: 0x15b95c0        getaddrinfo     function: 0x7f5d2c2ded80
table: 0x15b95c0        gethostname     function: 0x7f5d2c2deb20
table: 0x15b95c0        toip    function: 0x7f5d2c2df1d0
table: 0x15b95c0        getnameinfo     function: 0x7f5d2c2deba0
table: 0x15b95c0        tohostname      function: 0x7f5d2c2df140
table: 0x15b9410        __unload        function: 0x7f5d2c2dc510
table: 0x15b9410        choose  function: 0x15bb6b0
table: 0x15b9410        sink    function: 0x15badc0
table: 0x15b9410        sourcet table: 0x15bb6e0
table: 0x15bb6e0        contents:-----------------------------------------------
table: 0x15bb6e0        default function: 0x15baee0
table: 0x15bb6e0        by-length       function: 0x15bae00
table: 0x15bb6e0        until-closed    function: 0x15baee0
table: 0x15b9410        skip    function: 0x7f5d2c2dc520
table: 0x15b9410        _VERSION        LuaSocket 3.0-rc1
table: 0x15b9410        source  function: 0x15bafd0
table: 0x15b9410        sleep   function: 0x7f5d2c2dc6b0
table: 0x15b9410        udp     function: 0x7f5d2c2e1450
table: 0x15b9410        BLOCKSIZE       2048
table: 0x15b9410        tcp     function: 0x7f5d2c2e0b30
table: 0x15b9410        _SETSIZE        1024
table: 0x15b9410        sinkt   table: 0x15bb730
table: 0x15bb730        contents:-----------------------------------------------
table: 0x15bb730        default function: 0x15bb7e0
table: 0x15bb730        close-when-done function: 0x15bb780
table: 0x15bb730        keep-open       function: 0x15bb7e0
table: 0x15b9410        newtry  function: 0x7f5d2c2dfe70
table: 0x15b9410        select  function: 0x7f5d2c2e0360
table: 0x15b9410        try     function: 0x15bbeb0
table: 0x15b9410        bind    function: 0x15b94c0
table: 0x15b9410        connect6        function: 0x15bbe50
table: 0x15b9410        protect function: 0x7f5d2c2dfda0
table: 0x15b9410        gettime function: 0x7f5d2c2dc7b0
table: 0x15b9410        connect4        function: 0x15b9640
table: 0x15b9410        connect function: 0x7f5d2c2e0780
table: 0x15b9410        udp6    function: 0x7f5d2c2e1440
table: 0x15b9410        tcp6    function: 0x7f5d2c2e0b20


> print_tbl(s.dns.getnameinfo('127.0.0.1'))
table: 0x15ca660        contents:-----------------------------------------------
table: 0x15ca660        1       localhost
> print_tbl(s.dns.getnameinfo('192.168.1.1'))
table: 0x15b3cb0        contents:-----------------------------------------------
table: 0x15b3cb0        1       192.168.1.1
> print_tbl(s.dns.getnameinfo('202.101.172.35'))
table: 0x15c9340        contents:-----------------------------------------------
table: 0x15c9340        1       hangzhou.zjhzptt.net.cn


[参考] 2.  http://luaforge.net/projects/
相关文章
|
1月前
Lua
Lua
13 0
|
10月前
|
Ubuntu 云计算 C++
C++与lua的结合,LuaBridge的使用及遇到的坑
C++与lua的结合,LuaBridge的使用及遇到的坑
Lua 函数
Lua 函数
163 0
Lua 函数
|
存储 Java C语言
Lua 基础
Lua 基础语法及示例
568 0
Lua 基础
|
API Go
Lua相关的知识
http://stackoverflow.com/questions/5438751/how-to-debug-lua-remotely http://cn.bing.com/search?q=org.
895 0