public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: luacheck configuration for pandoc Lua filters?
Date: Thu, 13 May 2021 09:46:33 +0200	[thread overview]
Message-ID: <87mtszyt2e.fsf@zeitkraut.de> (raw)
In-Reply-To: <c4190975-7e98-446a-94a3-9f3df0e344b4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>


Norman Ramsey <fellswalker-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> luacheck works with one module at a time, so all I need to do is figure out
> the _names_ of the callable objects.  I could poke at metatables or could
> assume conservatively that all objects are callable.  What I don't know how
> to do is find callable names that _aren't_ materialized in the `pandoc`
> table but are available only via an `__index` metamethod.

We don't do any metatable magic on the pandoc module itself, so
iterating over the module table should give us all objects. As BPJ
points out, some functions are actually callable tables, so we have to
check for those. Also, the three objects 'Block', 'Inline', and
'MetaValue' are callable, but always lead to errors when called.
Therefore, the following code should print all the names we are after:

    local dont_call = pandoc.List{'Block', 'Inline', 'MetaValue'}

    for k, v in pairs(pandoc) do
      if not dont_call:includes(k) and
        (type(v) == 'function' or
         getmetatable(v) and getmetatable(v).__call) then
        print(k)
      end
    end

The refactored Lua subsystem that I'm working on will do away with these
silly inconsistencies -- just testing if an object has type "function"
will be enough.


> On Tuesday, May 11, 2021 at 4:21:47 AM UTC-4 BP wrote:
>
>> Den tis 11 maj 2021 01:16Norman Ramsey <fells...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>>
>>> I've recently discovered `luacheck`, a fantastic static-analysis tool for
>>> Lua programs.  I'd like to use it with my Pandoc filters, but it needs a
>>> configuration to tell it what functions in the global `pandoc` table are OK
>>> to call.  If anybody happens to have made such a configuration, please let
>>> us know.
>>
>>
>> I guess the fact that most of the constructors in the pandoc library are
>> actually callable objects rather than functions may be a problem one way or
>> another.


--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


  parent reply	other threads:[~2021-05-13  7:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10 23:16 Norman Ramsey
     [not found] ` <7fd5e3eb-99cd-4bce-84c4-313077e96637n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-05-11  8:21   ` BPJ
     [not found]     ` <CADAJKhDRBLYw8E-J_8DWjcZsfYRuOiF24=dSbcEtXyLmrTkX8A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-05-12 18:36       ` Norman Ramsey
     [not found]         ` <c4190975-7e98-446a-94a3-9f3df0e344b4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-05-13  7:46           ` Albert Krewinkel [this message]
     [not found]             ` <87mtszyt2e.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2021-05-13 17:03               ` Norman Ramsey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mtszyt2e.fsf@zeitkraut.de \
    --to=albert+pandoc-9eawchwdxg8hfhg+jk9f0w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).