0

系统配置:

OS: Windows 7 x64

lua -v
  Lua 5.1.4

luarocks -v
  2.2.0beta1

luarocks list
  luasocket
    3.0rc1-1 (installed) - C:/Program Files (x86)/LuaRocks/systree/lib/luarocks/rocks

luarocks show luasocket
   LuaSocket 3.0rc1-1 - Network support for the Lua language

    LuaSocket is a Lua extension library that is composed by two parts: a C core
    that provides support for the TCP and UDP transport layers, and a set of Lua
    modules that add support for functionality commonly needed by applications that
    deal with the Internet.

    License:        MIT
    Homepage:       http://luaforge.net/projects/luasocket/
    Installed in:   C:\Program Files (x86)\LuaRocks\systree

    Modules:
        ltn12 (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/ltn12.lua)
        mime (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/mime.lua)
        mime.core (C:\Program Files (x86)\LuaRocks\systree/lib/lua/5.1/mime/core.dll)
        socket (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/socket.lua)
        socket.core (C:\Program Files (x86)\LuaRocks\systree/lib/lua/5.1/socket/core.dll)
        socket.ftp (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/socket/ftp.lua)
        socket.headers (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/socket/headers.lua)
        socket.http (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/socket/http.lua)
        socket.smtp (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/socket/smtp.lua)
        socket.tp (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/socket/tp.lua)
        socket.url (C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/socket/url.lua)

luarocks path
  SET LUA_PATH=C:\Users\Zequez\AppData\Roaming/luarocks/share/lua/5.1/?.lua;
  C:\Users\Zequez\AppData\Roaming/luarocks/share/lua/5.1/?/init.lua;
  C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/?.lua;
  C:\Program Files (x86)\LuaRocks\systree/share/lua/5.1/?/init.lua;
  C:\Program Files (x86)\LuaRocks\2.2\lua\?.lua;
  C:\Program Files (x86)\LuaRocks\2.2\lua\?\init.lua;
  SET LUA_CPATH=C:\Users\Zequez\AppData\Roaming/luarocks/lib/lua/5.1/?.dll;
  C:\Program Files (x86)\LuaRocks\systree/lib/lua/5.1/?.dll;
  .\?.dll;
  .\?51.dll;
  C:\ProgramFiles (x86)\LuaRocks\2.2\?.dll;
  C:\Program Files (x86)\LuaRocks\2.2\?51.dll;
  C:\Program Files (x86)\LuaRocks\2.2\clibs\?.dll;
  C:\Program Files (x86)\LuaRocks\2.2\clibs\?51.dll;
  C:\Program Files (x86)\LuaRocks\2.2\loadall.dll;
  C:\Program Files (x86)\LuaRocks\2.2\clibs\loadall.dll
      SET LUA_CPATH=C:\Users\Zequez\AppData\Roaming/luarocks/lib/lua/5.1/?.dll;
  C:\Program Files (x86)\LuaRocks\systree/lib/lua/5.1/?.dll;
  .\?.dll;
  .\?51.dll;
  C:\Program Files (x86)\LuaRocks\2.2\?.dll;
  C:\Program Files (x86)\LuaRocks\2.2\?51.dll;
  C:\Program Files (x86)\LuaRocks\2.2\clibs\?.dll;
  C:\Program Files (x86)\LuaRocks\2.2\clibs\?51.dll;
  C:\Program Files (x86)\LuaRocks\2.2\loadall.dll;
  C:\Program Files (x86)\LuaRocks\2.2\clibs\loadall.dll

我是 Lua 的新手,我不习惯在 Windows 上编译东西。

无论如何,安装luasocket完成没有错误,用 MS Visual Studio 2010 编译所有东西。不得不luarocks从 Visual Studio 命令提示符运行,但它终于奏效了。

但是当我尝试要求它时,我会遇到错误。

> require 'socket'
error loading module 'socket.core' from file 'C:\Program Files (x86)\LuaRocks\systree/lib/lua/5.1/socket\core.dll':
        C:\Program Files (x86)\LuaRocks\systree/lib/lua/5.1/socket\core.dll:1: '=' expected near 'É'
stack traceback:
        [C]: ?
        [C]: in function 'require'
        ...iles (x86)\LuaRocks\systree/share/lua/5.1/socket.lua:12: in main chunk
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: ?

使用require 'luarocks.loader'也无济于事,同样的错误。luarocks我想我无论如何都不需要它,因为我已经用路径设置了 LUA_PATH

我搜索了几个小时没有结果。我还尝试安装旧版本的 Luasockets,但它需要 Visual Studio 2003,所以我想避免这种情况。

4

1 回答 1

2

看起来 Lua 正在尝试将 DLL 解析为 Lua 代码。如果package.path(或LUA_PATH环境变量)包含?.dll路径模板,则可能会发生这种情况。请从中删除所有?.dll模板package.path并将它们放入package.cpath(或LUA_CPATH环境变量)。

于 2014-07-21T16:25:46.263 回答