pandoc-lua 无法加载系统范围的模块。

huangapple go评论51阅读模式
英文:

pandoc-lua cannot load system wide modules

问题

在Lua解释器中,我有:

Lua 5.4.4  版权所有 (C) 1994-2022 Lua.org, PUC-Rio
> require('socket')
table: 0x55edf33e82d0	/usr/share/lua/5.4/socket.lua

在pandoc-lua中,我有:

Lua 5.4.4  版权所有 (C) 1994-2022 Lua.org, PUC-Rio
嵌入在pandoc 3.1.3
> require('socket')
stdin:1: 模块 'socket' 未找到:
	没有字段 package.preload['socket']
	没有文件 '/usr/local/share/lua/5.4/socket.lua'
	没有文件 '/usr/local/share/lua/5.4/socket/init.lua'
	没有文件 '/usr/local/lib/lua/5.4/socket.lua'
	没有文件 '/usr/local/lib/lua/5.4/socket/init.lua'
	没有文件 './socket.lua'
	没有文件 './socket/init.lua'
	没有文件 '/usr/local/lib/lua/5.4/socket.so'
	没有文件 '/usr/local/lib/lua/5.4/loadall.so'
	没有文件 './socket.so'
堆栈回溯:
	stdin:1: 在主块中

我尝试通过追加正确的目录来更改pandoc-lua中的package.path:

> package.path = package.path .. '/usr/share/lua/5.4/?.lua'
> require('socket')
/usr/share/lua/5.4/socket.lua:12: 模块 'socket.core' 未找到:
	没有字段 package.preload['socket.core']
	没有文件 '/usr/local/share/lua/5.4/socket/core.lua'
	没有文件 '/usr/local/share/lua/5.4/socket/core/init.lua'
	没有文件 '/usr/local/lib/lua/5.4/socket/core.lua'
	没有文件 '/usr/local/lib/lua/5.4/socket/core/init.lua'
	没有文件 './socket/core.lua'
	没有文件 './socket/core/init.lua'
	没有文件 '/usr/share/lua/5.4/socket/core.lua'
	没有文件 '/usr/local/lib/lua/5.4/socket/core.so'
	没有文件 '/usr/local/lib/lua/5.4/loadall.so'
	没有文件 './socket/core.so'
	没有文件 '/usr/local/lib/lua/5.4/socket.so'
	没有文件 '/usr/local/lib/lua/5.4/loadall.so'
	没有文件 './socket.so'
堆栈回溯:
	/usr/share/lua/5.4/socket.lua:12: 在主块中
	[C]: 在函数 'require' 
	stdin:1: 在主块中

现在出现了找不到'socket.core'的问题...

我以为pandoc-lua可以加载系统上可用的任何Lua包。我已经花了很多时间尝试其他解决方案,并浏览了网页,但没有找到解决方法。是否有人看到了错误?

谢谢!

我只是试图在我的系统(Debian Testing)中加载Lua模块,以在pandoc过滤器中尝试使用pyluatex代码的思想。

英文:

In lua interpreter, I have:

Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
> require('socket')
table: 0x55edf33e82d0	/usr/share/lua/5.4/socket.lua

In pandoc-lua, I have:

Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
Embedded in pandoc 3.1.3
> require('socket')
stdin:1: module 'socket' not found:
	no field package.preload['socket']
	no file '/usr/local/share/lua/5.4/socket.lua'
	no file '/usr/local/share/lua/5.4/socket/init.lua'
	no file '/usr/local/lib/lua/5.4/socket.lua'
	no file '/usr/local/lib/lua/5.4/socket/init.lua'
	no file './socket.lua'
	no file './socket/init.lua'
	no file '/usr/local/lib/lua/5.4/socket.so'
	no file '/usr/local/lib/lua/5.4/loadall.so'
	no file './socket.so'
stack traceback:
	stdin:1: in main chunk

I tried to change package.path in pandoc-lua by appending the correct directory:

> package.path = package.path .. ';/usr/share/lua/5.4/?.lua'
> require('socket')
/usr/share/lua/5.4/socket.lua:12: module 'socket.core' not found:
	no field package.preload['socket.core']
	no file '/usr/local/share/lua/5.4/socket/core.lua'
	no file '/usr/local/share/lua/5.4/socket/core/init.lua'
	no file '/usr/local/lib/lua/5.4/socket/core.lua'
	no file '/usr/local/lib/lua/5.4/socket/core/init.lua'
	no file './socket/core.lua'
	no file './socket/core/init.lua'
	no file '/usr/share/lua/5.4/socket/core.lua'
	no file '/usr/local/lib/lua/5.4/socket/core.so'
	no file '/usr/local/lib/lua/5.4/loadall.so'
	no file './socket/core.so'
	no file '/usr/local/lib/lua/5.4/socket.so'
	no file '/usr/local/lib/lua/5.4/loadall.so'
	no file './socket.so'
stack traceback:
	/usr/share/lua/5.4/socket.lua:12: in main chunk
	[C]: in function 'require'
	stdin:1: in main chunk

Now it's the socket.core which is not found...

I thought that pandoc-lua could load any lua package available on the system. I've spent a lot of time trying other solutions, and browsing the web, but did not find the solution. Does any see the error?

Thanks!

I am just trying to load lua module available on my system (Debian Testing) in pandoc filters.

My ultimate goal is to try to use the ideas from the code of pyluatex in a pandoc lua filter.

答案1

得分: 2

我认为这里存在两个问题:路径似乎没有正确设置;即使正确设置了,可能还需要满足一些进一步的条件。

关于前者:您需要设置package.cpath,它应该指向/usr/<your system lib folder>/lua/5.4/?.so。lua-socket包还安装了一些.so文件,它们也位于LUA_CPATH下:core.soserial.sounix.so等等。

(另外,通常情况下,package.path应该包括/usr/share/lua/5.4/?/init.lua,因为这是某些包的入口点。)

我认为设置这些的最直接方式是通过环境变量LUA_PATHLUA_CPATH

假设LUA_PATHLUA_CPATH都正确设置了,那么pandoc可执行文件需要动态链接才能使用已编译的lua模块:

来自pandoc.org的说明:

可执行文件是静态链接的,没有动态依赖项或对外部数据文件的依赖。注意:由于静态链接,此软件包的pandoc二进制文件无法使用需要外部用C编写的lua模块的lua过滤器。

Debian软件包可能是静态链接的;GitHub发布的二进制文件也是如此。如果通过cabal从源代码编译,它可以导入已编译的模块。不确定通过cabal获取最新发布版的情况。

英文:

I think there are two issues here: the paths don't seem to be set correctly; and even if they were set correctly, it's possible that some further conditions need to be met.

As to the former: You need to set package.cpath as well, which would point to /usr/&lt;your system lib folder&gt;/lua/5.4/?.so. The lua-socket package installs several .so files as well under LUA_CPATH: core.so, serial.so, unix.so, etc.

(Also, in general package.path should include /usr/share/lua/5.4/?/init.lua, since that's the entry point for some packages.)

I think the most straightforward way of setting these is via the environment variables, LUA_PATH and LUA_CPATH.

Assuming that LUA_PATH and LUA_CPATH are both correctly set, the pandoc executable needs to be dynamically linked for compiled lua modules to work:

from pandoc.org

> The executable is statically linked and has no dynamic dependencies or dependencies on external data files. Note: because of the static linking, the pandoc binary from this package cannot use lua filters that require external lua modules written in C.

The debian package is probably statically linked; so is the binary available on github releases. If you compile from source via cabal, it can import compiled modules. Not sure about getting the latest release via cabal.

huangapple
  • 本文由 发表于 2023年6月11日 22:10:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76450876.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定