From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30604 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Shane Liesegang Newsgroups: gmane.text.pandoc Subject: Re: How to tell an Inlines object from a table in a Lua filter? Date: Mon, 23 May 2022 23:49:43 -0700 (PDT) Message-ID: <0a182969-9df6-4462-aae8-28f34d5b2e37n@googlegroups.com> References: <84bdd685-384d-4fc4-bee5-75344028f42fn@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_146_1874836888.1653374983239" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20026"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBC2OTJELV4GRBCEAWKKAMGQEHGR2SFI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue May 24 08:49:48 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f185.google.com ([209.85.167.185]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ntOMV-0004zU-9H for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 24 May 2022 08:49:47 +0200 Original-Received: by mail-oi1-f185.google.com with SMTP id s74-20020acaa94d000000b0032b1e4c0a33sf2367246oie.19 for ; Mon, 23 May 2022 23:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=0fKJ1wIW0KFf80cnHLphdyfBGNRyP7d14ZXXj7zrOsU=; b=YC92GJZtHA6aBMElcjcyODlV4Fs0+jvKShRbeyRPc8s+NbaZsQ0jeV5vkF76CGS7RL XtI1AacYtXQAa7RtMLoxNwIDZ7O9eyK6BLikp2B/ah6JHczbhV7IoXxSME30FcaABhO3 aD/mkTF2suw/aPBmyqZc8j9E240VmH6Ag2FTtxMfjYdJjquMwy6DWmj1nRbFlR371Jq2 l0QFHk4UXEBRMuAFAJ5XNFYxwdHpa7w3f4XiTiViTBWu5O6IlXUl5rrZkNVJ1IwRoQkB xkWpHvNWAivkX5eTyJDefYGkyoDLw1XxLN7mjqs6yYLFP3ha4LM3cAjisjxcH279ASei WsqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=0fKJ1wIW0KFf80cnHLphdyfBGNRyP7d14ZXXj7zrOsU=; b=iQFHfuby5Eh4p6EkSCj7p3x3iZ6lIPsnd9R9MXKHiMcDvDx/PVH3opjdPqsG1ycNOC KeJ9qIQsgmlAvGFeVU5xmnIn907MsI4Xo8miL1CvtVHWJZMdNIgQmdRPOn01Y2/+XxeG 7Mogyq1gJ83PkddFSJerHmlaaDZSavK27WeSG/Z90jgqSl7RhRyWUIpU9AiSDDHrsIKP +nU8zIPY3OEB5QEi+FJR568qbDJydAJw4yU+M710hhLnjajD6jC5b1ajjZIVO9rcqm+t pt+JQLDCW6u0faZVfh8yzu5EUrpl6vau4GkGsrB//TW1XyOGxEyqDMqc4mFOIDdAp10m 7HAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=0fKJ1wIW0KFf80cnHLphdyfBGNRyP7d14ZXXj7zrOsU=; b=mfuD2owWGN0sBpR50/72FSAlrZbaIIm3l6lrZHpa7G8noMkWT5JjIkqNLmgTeMflUh gopx9D6f3uRh1g+VrXu8pN9uYQxl9gnbvuy2048uLSWJzBTQZFaIPEv+zPQ9VCaXhmPL B2WQZVIfbJ/pZjIXcsCzBQbC2SA86i3Gr8y40WZHgAFlUyXUL39KvmaozKJ3TmN5p2Sc LNqiOCRKrI98xCz/5iYVIlwf1xoixvSXGXx46QJKzfH3mNkhnWcQYlIuM5sxCHqedih4 Atu2fqi7zXLDtHQaYRouxp6l4XMfWPjQUc3Mcx4BHn5o8dIwAQZ4q+xRStlUdiiyA4DS 7nDA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532Au/3pq7gGNTUYHA/jHzh0hCiF3Ko+HhMKJ89oeJXxMDlh4hMU QJVFr7KTweQyt7JKHsVrR9E= X-Google-Smtp-Source: ABdhPJzfHDut4tAxw6hOSIgi2SuTUTf0d2oTFK9RHjtWBH/nIS1dHpIU85n1X8wY8WMdfZgPerFWDw== X-Received: by 2002:a05:6870:a410:b0:f1:b21a:a160 with SMTP id m16-20020a056870a41000b000f1b21aa160mr1514621oal.162.1653374986282; Mon, 23 May 2022 23:49:46 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:a1a0:b0:d7:1d2b:ec1a with SMTP id a32-20020a056870a1a000b000d71d2bec1als6100177oaf.3.gmail; Mon, 23 May 2022 23:49:44 -0700 (PDT) X-Received: by 2002:a05:6870:a90a:b0:f1:b878:1c77 with SMTP id eq10-20020a056870a90a00b000f1b8781c77mr1656755oab.0.1653374983937; Mon, 23 May 2022 23:49:43 -0700 (PDT) In-Reply-To: <84bdd685-384d-4fc4-bee5-75344028f42fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: liesegang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:30604 Archived-At: ------=_Part_146_1874836888.1653374983239 Content-Type: multipart/alternative; boundary="----=_Part_147_1398775338.1653374983239" ------=_Part_147_1398775338.1653374983239 Content-Type: text/plain; charset="UTF-8" I've figured out a workaround, but just wondering if there's a better way than diving into the metatables: ~~~ function fix_table_strings(t) for k, v in pairs(t) do if type(v) == "table" then local metatable = getmetatable(v) if metatable ~= nil and metatable.__name == "Inlines" then t[k] = pandoc.utils.stringify(v) else fix_table_strings(t[k]) end end end end ~~~ On Tuesday, May 24, 2022 at 9:30:41 AM UTC+3 Shane Liesegang wrote: > Is there a way to tell whether a given object is a pandoc.Inlines as > opposed to a plain Lua table? When I call `type(obj)` on it, it just > returns "table." I note that if I print it, it shows "Inlines:" instead of > "table:" but is there any smarter way to determine? > > I see some code in the Lua filters example repository > > that does this kind of check, but I don't know if it's crucial to that code > or not, if something has changed recently, etc. > > (My use case here is walking through my Meta object and building something > that will get passed to different functions -- if it encounters a nested > table of data, I need to recurse, but if it's an Inlines object, I want to > stringify it.) > > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/0a182969-9df6-4462-aae8-28f34d5b2e37n%40googlegroups.com. ------=_Part_147_1398775338.1653374983239 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I've figured out a workaround, but just wondering if there's a better = way than diving into the metatables:

~~~
function fix_table_strings(t)
  for k, v in pairs(t) do
&n= bsp;   if type(v) =3D=3D "table" then
      local me= tatable =3D getmetatable(v)
      if metatable ~=3D nil a= nd metatable.__name =3D=3D "Inlines" then
        t[= k] =3D pandoc.utils.stringify(v)
      else
  &nb= sp;     fix_table_strings(t[k])
      end
&n= bsp;   end
  end
end
~~~

On Tuesday, May 24,= 2022 at 9:30:41 AM UTC+3 Shane Liesegang wrote:
Is there a way to tell whether a g= iven object is a pandoc.Inlines as opposed to a plain Lua table? When I cal= l `type(obj)` on it, it just returns "table." I note that if I pr= int it, it shows "Inlines:" instead of "table:" but is = there any smarter way to determine?

I see some code in the Lua filters example repository that does this= kind of check, but I don't know if it's crucial to that code or no= t, if something has changed recently, etc.

(M= y use case here is walking through my Meta object and building something th= at will get passed to different functions -- if it encounters a nested tabl= e of data, I need to recurse, but if it's an Inlines object, I want to = stringify it.)=C2=A0

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/0a182969-9df6-4462-aae8-28f34d5b2e37n%40googlegroups.= com.
------=_Part_147_1398775338.1653374983239-- ------=_Part_146_1874836888.1653374983239--