在 Eclipse 中使用 luasocket 时出错 (Ubuntu 16.04)

Error using luasocket in Eclipse (Ubuntu 16.04)

我正在尝试在安装在 Ubuntu 16.04 的 Eclipse Luna 中使用 Lua 5.1 和 lua 套接字。

我已经安装了 Lua 5.1 和 LuaSocket 3.0-rc1,我可以从命令行 运行 这个程序(lua main.lua ):

print(_VERSION)
print("Path: "..package.path..'\nCPATH: '..package.cpath)
socket = require("socket")
print(socket._VERSION)

结果是:

$ lua main.lua
Lua 5.1
Path: ./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua
CPATH: ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
LuaSocket 3.0-rc1

但是当我尝试使用安装了 lua 插件的 eclipse 运行 相同的程序时,我得到了这个:

Lua 5.1
Path: ;./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?.lua;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?/init.lua;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?.luac;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?/init.luac;
CPATH: ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
Exception in thread "main" com.naef.jnlua.LuaRuntimeException: 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: lua_gettop
    at com.naef.jnlua.LuaState.lua_pcall(Native Method)
    at com.naef.jnlua.LuaState.call(LuaState.java:555)
    at org.eclipse.ldt.support.lua51.internal.interpreter.JNLua51Launcher.run(JNLua51Launcher.java:128)
    at org.eclipse.ldt.support.lua51.internal.interpreter.JNLua51Launcher.main(JNLua51Launcher.java:143)

有什么想法吗?你能帮帮我吗?

谢谢 亚历山大

前段时间discussed on the lua maillist也有同样的问题,看看那里的推荐对你有没有帮助:

By default, LDT ships with a built-in Lua VM (based on jnLua) so as anyone without even having to install Lua on its machine can start running Lua scripts real quick. I think that the way you've set the PATH and CPATH, the jnLua VM itself is not found anymore.

What you probably want is to configure a "local interpreter" for your local native VM. You can use [1] as a reference. Once you have the interpreter set up, you can launch the script against this interpreter instead of the embedded jnLua one by tweaking your launch configuration.