Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua filters: notes on v2.16.1 differences #7657

Closed
wlupton opened this issue Nov 3, 2021 · 4 comments
Closed

Lua filters: notes on v2.16.1 differences #7657

wlupton opened this issue Nov 3, 2021 · 4 comments

Comments

@wlupton
Copy link
Contributor

wlupton commented Nov 3, 2021

All my filters are now working fine with 2.16.1, but I wanted to list a few things that I've noticed, some of which might be unintentional. I'm happy to create new issues for anything that might result in a future change. I'm also happy to contribute to the best of my ability (which sadly doesn't include Haskell programming).

Userdata pairs() include 'tag', nil values and functions

I noticed that the attributes returned by pairs() include tag, several nil values (for attributes that don't necessarily apply to the element type) and various functions. It's easy to ignore them, but I wondered whether it was intentional.

Text
function Para(para)
    for n, v in pairs(para) do
        io.stderr:write(n .. ' ' .. tostring(v) .. '\n')
    end
end
% pandoc para.md -L pairs.lua
attr nil
bodies nil
caption nil
colspecs nil
content table: 0x7fd29960ad20
foot nil
format nil
head nil
level nil
listAttributes nil
tag Para
text nil
clone function: 0x7fd299413140
show function: 0x7fd2994132c0
<p>Text</p>

Missing argument error messages

Omitting the src argument from the Image() constructor gives a strange string expected, got string message:

![](Cat.png){#id .class width=420}
function Image(image)
    local new_image = pandoc.Image(image.caption)
end
% pandoc image.md -L image.lua
Error running filter image.lua:
string expected, got string
	while retrieving function argument src
	while retrieving arguments for function Image

Pandoc 2.14.1 (presumably unintentionally?) permits this:

% pandoc-2.14.1 image.md -L image.lua
<p><img src="Cat.png" id="id" class="class" width="420" /></p>

Don't get me wrong: it's great that the error is caught and reported.

AttributeList constructor (and constructor docs in general)

The 2.15 release notes mention AttributeList() but I didn't see any info on how to use it.

More generally, I feel that the lua constructor documentation is rather sparse. Compare pandoc.Image, which states the data type of each field, with pandoc.Image(), which is quite vague. For example, I think that caption can in fact be either a string or a list of Inlines?

@tarleb
Copy link
Collaborator

tarleb commented Nov 3, 2021

Thanks, it's a relieve to know that things are working ok again.

The pairs behavior is a bug, at least with regard to the inclusion of nil values. Having object methods in there was intentional, but I hadn't thought about pandoc when I wrote that code. Maybe this is a mistake, too? Please raise a new issue, either here or at https://github.com/hslua/hslua/.

I plan to generate the constructor documentation from the Haskell code, and to make the docs accessible from within the Lua interpreter. It's probably worth a separate issue, too.

@wlupton
Copy link
Contributor Author

wlupton commented Nov 3, 2021

Thanks. I'll raise issues as requested. What about item 2 "Missing argument error messages"?

@tarleb
Copy link
Collaborator

tarleb commented Nov 3, 2021

I had missed that somehow. Definitely a bug in hslua. I'll raise one there.

@wlupton
Copy link
Contributor Author

wlupton commented Nov 3, 2021

OK, I think that all the issues raised here are now covered in their own tickets, so I'll close this one.

@wlupton wlupton closed this as completed Nov 3, 2021
tarleb added a commit that referenced this issue Nov 4, 2021
This fixes issues with

  - misleading error messages when a required function parameter is
    omitted;
  - absent properties still being listed in the output of `pairs`; and
  - alias accessing leading to errors instead of returning `nil`, e.g.
    with `(pandoc.Str '').identifier`.

Fixes: #7661
See also: #7657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants