如何在构建中包含Lua模块

时间:2013-11-14 16:24:45

标签: api module lua

我下载了this Lua模块并使用make安装了它。但是,当我尝试在我的代码中使用它时,我收到以下错误:

VirtualBox:~/Downloads$ lua socket_test.lua 
lua: socket_test.lua:1: module 'nixio.util' not found:
    no field package.preload['nixio.util']
    no file './nixio/util.lua'
    no file '/usr/local/share/lua/5.1/nixio/util.lua'
    no file '/usr/local/share/lua/5.1/nixio/util/init.lua'
    no file '/usr/local/lib/lua/5.1/nixio/util.lua'
    no file '/usr/local/lib/lua/5.1/nixio/util/init.lua'
    no file '/usr/share/lua/5.1/nixio/util.lua'
    no file '/usr/share/lua/5.1/nixio/util/init.lua'
    no file './nixio/util.so'
    no file '/usr/local/lib/lua/5.1/nixio/util.so'
    no file '/usr/lib/i386-linux-gnu/lua/5.1/nixio/util.so'
    no file '/usr/lib/lua/5.1/nixio/util.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file './nixio.so'
    no file '/usr/local/lib/lua/5.1/nixio.so'
    no file '/usr/lib/i386-linux-gnu/lua/5.1/nixio.so'
    no file '/usr/lib/lua/5.1/nixio.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    socket_test.lua:1: in main chunk
    [C]: ?

我的代码的第一行:

local nixio = require "nixio", require "nixio.util"

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:4)

我看到了这些选项:

  1. 尝试make install并希望它有效。也许设置一些变量,例如PREFIX没有。

  2. 手动将dist/usr/local/share/lua/5.1/nixio移至/usr/local/share/lua/5.1/nixio,将dist/usr/local/lib/lua/5.1/nixio.so移至/usr/local/lib/lua/5.1/nixio.so

  3. dist路径添加到环境中:LUA_CPATH='dist/usr/local/lib/lua/5.1/?.so;;'LUA_PATH='dist/usr/local/share/lua/5.1/?.lua;;'

  4. 在Lua中添加dist路径:package.cpath='dist/usr/local/lib/lua/5.1/?.so;'..package.cpathpackage.path='dist/usr/local/share/lua/5.1/?.lua;'..package.path