From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30548 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Lua REPL for filters Date: Thu, 12 May 2022 17:38:21 +0200 Message-ID: <87ilqazpem.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28556"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCZJF7XJTILRBJXL6SJQMGQER4HEBHA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu May 12 18:28:26 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ed1-f59.google.com ([209.85.208.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1npBfu-0007IM-3i for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 12 May 2022 18:28:26 +0200 Original-Received: by mail-ed1-f59.google.com with SMTP id r26-20020a50aada000000b00425afa72622sf3367974edc.19 for ; Thu, 12 May 2022 09:28:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1652372905; cv=pass; d=google.com; s=arc-20160816; b=vIVEBfArjARhL2Iji+k8VXA2SPPkbPPW2pNy4raN+xMymfk3uA9lne+9RxTdb3ggtO BAzx9Q22EdyOplonl4z+1qYtWApRuCbU0f3FV/lPWTZ2b/giOIdva5ZeixVWGd6jk9Y7 xbS/P7zlwk1KMWMLaK2Aj5H+ynZ8ZTI/1eF1p9Owgwe8ufq0oG12Y/WozXwaw0l+EQsH cdKb9qY83dUVcgoEZ3Ptl7PTP9zmcrefW/6ZKw1jkW8IoUYY/brAYyNG220r3sulNqzM MQaa/o02SR2bUxFpY36smkE4U4qUcv3H+HwOt05KTZtduJI2jAujbTNu1/qURdIW3JR5 AvCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:mime-version:message-id :date:subject:to:from:sender:dkim-signature; bh=Bl/WMX1rFiYxe7rRNpEPwpw2sMDvDuiKY49k1NoQUOQ=; b=E5VcWIAkMTVF0r1esDofIwmaLBpIpFNdmcNL2n8L3GF/wPP4nCAeRyjdVuBr1c8JgS xMOPp8kZUu6CRGRLSHzUgzn+7E8no6WdXac45rG1ng21C8V/9MGDnvpxSaI9Acn6ETa1 0BYbXK+xYyae22nJodsJUMzWlnVaGzWl/sdCWhdmkImNTR2U2B//qmhESY+u1mHdD7Kf kZ101fS2/gzBNEPdfDQmp1E+LFz35WIgTK2jivI88WG7l9GHr3lryV9+0G0jVabcqL1A JiyHhTw0VXIWUl2A5+4Ig48Nyv1X+H8CXxTYGeis9cW2CcDNoEcyP3Y7zMAg18XbA40x 8w5g== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.151 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Bl/WMX1rFiYxe7rRNpEPwpw2sMDvDuiKY49k1NoQUOQ=; b=hh720asJlvfFgnDqiUZ994KaENLVGJV+e38zxeZ9ZBhmBO+VIPneTphvEL2Hishs5e 5LAet9yCaxs+28Pm5Wm9Qu6sXRzpmH7Suny42cM38ajFkTKQsuloSHmoyyy9beX0HT7r 6ddCyQY3EbaWwLgaaTQ1NjxfCm8vJZKmj1NshqQP4JdpPy4sNhZfLVnshgqKQF+timBq gE1/W/wEpEDuLgT900A1OU1nQW9jckLeFe/IHA6dQBdbJtIOHhg83j34mihCXaVAgoBE uAv5Ot2UaUmGrcgWg6FrOqSK23jgeEe7Ch9gacGs3ESSynip0sW/EdPo2k1DgqHtfldC UziQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=Bl/WMX1rFiYxe7rRNpEPwpw2sMDvDuiKY49k1NoQUOQ=; b=GCaHvqW/RwBMBAhx8vRpnww6zkR/8Fkt11cr+YTF7JMXMxQhIghM0eyc7bS4QTclwz 87N4tvg9zy8GOibNAsrREQGocgbGI2O4R54pT0V6AliIJ1Z/YPFJxXlz3FifuJpT2FIe V4eD3dOu/5Xu9gv2PZgn3I54wAf20qiqp/AqiYTNIxlRUZ+fO56h4w8EAYC7OOFsgc3w GcmmLmgABJAKyqnqhw0JjIkAu6SCSGqGCu0FJFdm4w+Apyddh6jhoQ3LlxLufhLMHeCK LrGv97JIWrVS/uHMluCIFitSNEXsuC9aW5CyDnMZMeCwnAM9DzfILJKoefrKn3ZW7UdF 7dgA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM531YrO2Ad7g93q7G4JCR/Sj9x5k+4eJli6baoCMFnOmN1+64SVip UbPaf7B11XG7Njx6vx1n/MQ= X-Google-Smtp-Source: ABdhPJwteH0lWAO11h8TX+L71I4+3wyh6kdI2bAWtF9E01vd7k3QKZhU+mqemQwI/x5ZVaJLxH2X7w== X-Received: by 2002:a17:907:60cf:b0:6f4:5128:233b with SMTP id hv15-20020a17090760cf00b006f45128233bmr663946ejc.239.1652372905815; Thu, 12 May 2022 09:28:25 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6402:26d2:b0:428:f87:ccd8 with SMTP id x18-20020a05640226d200b004280f87ccd8ls2345742edd.1.gmail; Thu, 12 May 2022 09:28:21 -0700 (PDT) X-Received: by 2002:a05:6402:1a36:b0:425:f96c:350f with SMTP id be22-20020a0564021a3600b00425f96c350fmr36173176edb.160.1652372901400; Thu, 12 May 2022 09:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652372901; cv=none; d=google.com; s=arc-20160816; b=G7TefK2DxREylHTgkcIzK6rF8eVWFniJhMEWS+wpeKEMxrbB89chGSy52DydeeKDqr yjJRp9gEBqqIw+R3U8dxuTUl53zRt6YIXbaDJKJSLD0Um7GC21lhSftxL0RTyBVageLK vO92BWE1h683oFJul+GER4q257KhUO+VX1+z0f3lan2nn15VmV7NGrB3btZk7rCt/Yby WjH67EMG1S8seJ1x/LHpdLmFIAnZJGLHX099kSTVTsW1CihrhQUlc58fEGywIAExkXfH LPquavktSefDf9PohihRCgUxACvTyofBHVaKgCu2mIFU35PNWWotbYT9Q5uiEMAmjZJN hsew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:subject:to:from; bh=pvsuRXxKHOoG8Rt3CjYKxuWbPXxV0bitxTGpRt61x1g=; b=D+VXeMs8qVULA6eqAaZQZ30ozWXCO5/1SXpzct7l8/HbdfVvPTmJ0kbEss0iVA98+q txVN/hOS2YjcZvLRSyTu+HWZF4Wp1/xB0F7FXd824mulpbwRCjL/loiADd6kM52J2+P0 yAYqEKgpfMJ3HwZvIstgpKbeMWl7KIdETpMXS+urBzZ59hlJZSwTmPYJcACVgUyqJWxu sZYwF8MXAmtiltwCV81cT/bSM1ueNfc3LocTY6qoTEEy3EiDJEkaiwKmOlVRHlzEmKRh S0Xrte2mSOzXX4/3MZavsrQte3YZmOrgPX0KqKe32oDnUS2vtXZij6UvMn4y7V6IFOcN GK4Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.151 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org Original-Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org. [80.241.56.151]) by gmr-mx.google.com with ESMTPS id z12-20020a50eb4c000000b0041cf5333d81si324079edp.4.2022.05.12.09.28.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 09:28:21 -0700 (PDT) Received-SPF: pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.151 as permitted sender) client-ip=80.241.56.151; Original-Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Kzcdt5Zc8z9sWG for ; Thu, 12 May 2022 18:28:18 +0200 (CEST) X-Rspamd-Queue-Id: 4Kzcdt5Zc8z9sWG X-Original-Sender: albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.151 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@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:30548 Archived-At: Here's a piece of code that can be used for interactive Lua filter development. It's crude, but should be usable nonetheless. https://gist.github.com/tarleb/fc6718bcfc74fd68f324d938cdb6f350 Usage: the prompt can be used to evaluate arbitrary Lua code and can be quit by typing `exit`, `quit`, `STOP = true`, or pressing `Ctrl-D`. The argument given to the `interactive` function is available via the variable `it`. The content of that variable will also be used as the function's return value once the repl is terminated. A second table can be passed to the function, the field of which will then become available as variables in the REPL. This can be useful to keep some global state. Example: -- Ensure that, if the REPL is quit via `STOP = true`, -- processing is skipped for **all remaining** `Str` elements, -- but not for the main `Pandoc` element. local Str_env = {STOP = false} Str = function (str) return interactive(str, Str_env) end Pandoc = interactive The REPL uses *readline* if readline.lua is available. Something like this had been requested a number of times; I hope the code will be useful. -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124