The `debug` library is not available in Lua filters

オープン
#1,012 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
lua, rust
領域
backend

調査の方向性

Start in crates/pampa/src/lua/filter.rs: inspect the filter environment setup around Lua::new() (lines 177–192) and the chunk name setup (lines 383–386). Reproduce with the supplied filter.lua and index.qmd using q2 render index.qmd --to html; compare with Quarto 1 if useful. Done when the filter can use debug.getinfo to obtain its running chunk path without dropping a path character.

索引モデルが issue の本文から書いたものです。

説明

Bug description

The global debug is nil in a Lua filter, so a call to debug.getinfo stops the render.

Extensions use this call to find the directory of the module that is running.
For example, a load_sibling helper that several of my extensions vendor reads debug.getinfo(1, "S").source, then loads a neighbouring file with require.
Three of the 40 extensions (all mine) I tested call debug.getinfo in their Lua files.
Quarto 1 runs Lua through Pandoc, which exposes the full debug library.

This is the Quarto 1 way of doing it, and a better way might be worth exploring in q2.
Both engines already cover the common cases without debug, which I checked on q2 and on Quarto 1.12.0:

  • A relative require("./b") in a nested module loads the neighbouring b.lua.
  • PANDOC_SCRIPT_FILE gives the path of the filter script.
  • quarto.utils.resolve_path resolves a path against the filter directory.

None of them gives a module its own path, and extensions that call debug.getinfo break today.

The filter environment uses Lua::new(), which skips debug as unsafe, although the comment says native builds load everything:

https://github.com/quarto-dev/q2/blob/a2a1cb948b1aec42c93200b880dc73567160f691/crates/pampa/src/lua/filter.rs#L177-L192

The chunk name of the filter script is set without a leading @, so once debug is loaded, source:sub(2) would still drop the first character of the path:

https://github.com/quarto-dev/q2/blob/a2a1cb948b1aec42c93200b880dc73567160f691/crates/pampa/src/lua/filter.rs#L383-L386

Steps to reproduce

filter.lua:

function Pandoc()
  return pandoc.Pandoc(pandoc.Para(pandoc.Str(debug.getinfo(1, "S").source)))
end

index.qmd:

---
filters:
  - filter.lua
---

x

Render it with q2 and with Quarto 1:

q2 render index.qmd --to html
quarto render index.qmd --to html
Actual behavior
Rendering single file: /private/tmp/q2-debug.Eqp8/index.qmd
error: while rendering /private/tmp/q2-debug.Eqp8/index.qmd
Error: Lua filter error: runtime error: [string "/private/tmp/q2-debug.Eqp8/filter.lua"]:2: attempt to index a nil value (global 'debug')
stack traceback:
    [string "/private/tmp/q2-debug.Eqp8/filter.lua"]:2: in function 'Pandoc'

1 error
Expected behavior

debug.getinfo(1, "S").source returns the path of the running chunk with a leading @, as in standard Lua.
Quarto 1 writes it into the page:

<p>@filter.lua</p>
Your environment
  • q2: Q2 (quarto 2) 0.40.0-nightly.20261101 (nightly built from a2a1cb9).
  • Quarto 1 for comparison: 1.12.0 (pre-release).
  • OS: macOS 27.2 (arm64).
  • Terminal, no IDE.
主要言語
Rust
スター
302
フォーク
22
平均マージ
5時間 8分
マージ済み PR(30日)
220

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

quarto-dev/q2 のほかの issue

quarto-dev/q2 の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。