我想通过一个大型的 lua 代码库来调试我的方式。为此,我下载了 ZeroBrane 并按照他们的说明设置捆绑的 mobdebug。
代码库是 koreader。以下 shellscript 重现了我所做的事情:
# dependencies for building koreader
sudo apt-get install build-essential git patch wget unzip \
gettext autoconf automake cmake libtool nasm luarocks libsdl2-dev \
libssl-dev libffi-dev libsdl2-dev libc6-dev-i386 xutils-dev linux-libc-dev:i386 zlib1g:i386
# get the source
git clone https://github.com/koreader/koreader.git
cd koreader && ./kodev fetch-thirdparty
# build it, this will take a long time
./kodev build
# assuming you have ZeroBrane installed
export ZBS=/opt/zbstudio
export LUA_PATH="./?.lua;$ZBS/lualibs/?/?.lua;$ZBS/lualibs/?.lua"
export LUA_CPATH="$ZBS/bin/linux/x86/?.so;$ZBS/bin/linux/x86/clibs/?.so"
# execute it, this will run lua
./kodev run
执行./kodev run
导致以下错误消息:
[*] Current time: 10/14/19-17:55:34
./luajit: ./datastorage.lua:3: module 'libs/libkoreader-lfs' not found:
no field package.preload['libs/libkoreader-lfs']
no file './libs/libkoreader-lfs.lua'
no file '/opt/zbstudio/lualibs/libs/libkoreader-lfs/libs/libkoreader-lfs.lua'
no file '/opt/zbstudio/lualibs/libs/libkoreader-lfs.lua'
no file '/opt/zbstudio/bin/linux/x86/libs/libkoreader-lfs.so'
no file '/opt/zbstudio/bin/linux/x86/clibs/libs/libkoreader-lfs.so'
stack traceback:
[C]: in function 'require'
./datastorage.lua:3: in main chunk
[C]: in function 'require'
./reader.lua:18: in main chunk
[C]: at 0x55a81bf25771
~/programming/koreader
如果没有 and 的定义LUA_PATH
,LUA_CPATH
则没有问题,并且 koreader 运行良好。所以我假设导入路径以某种方式损坏。如何正确设置?
也许这可以帮助你,如果我正确阅读了代码,./kodev run
将(在某些时候)执行这个:
-- set search path for 'require()'
package.path =
"common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" ..
package.path
package.cpath =
"common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" ..
package.cpath
libkoreader-lfs.so 的实际位置是:
/home/lklein/programming/koreader/base/build/x86_64-linux-gnu-debug/libs/libkoreader-lfs.so
确实,如果我将其附加到 CPATH
/home/lklein/programming/koreader/base/build/x86_64-linux-gnu-debug/?.so
然后它可以运行。lua 在这里做什么?如果没有设置,它是否总是假设一些默认的 LUA_PATH 和 LUA_CPATH?因为无需我指定任何路径,它就可以正常工作。