From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/33158 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: jcr Newsgroups: gmane.text.pandoc Subject: Re: requiring other lua files from parent directories from within filters Date: Thu, 5 Oct 2023 07:49:50 -0700 (PDT) Message-ID: <9c7ac85d-ae26-41b2-941e-088bad98c353n@googlegroups.com> References: <875y3lnzho.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_8986_1974259023.1696517390582" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11604"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDQLFNXWVILBBEE27OUAMGQEDGES3WA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Oct 05 16:49:55 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f186.google.com ([209.85.167.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qoPfn-0002ja-Ko for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 05 Oct 2023 16:49:55 +0200 Original-Received: by mail-oi1-f186.google.com with SMTP id 5614622812f47-3af64a4c931sf1685620b6e.2 for ; Thu, 05 Oct 2023 07:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1696517394; x=1697122194; darn=m.gmane-mx.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=QsF+SCrrqU5t7L1Xcc8mN5yYQjbk4+6NGkFsLVCpCTc=; b=H4TwTZxlpNm3uLdA0DNT+VyYYnAKotnSxxgmNX+U1V4FcxqHEcc3pIJYM68YBTDJua Ui1Obz49mIDwU8M5uhvQrkoRkyVMh4Aa5yHBqbfWshSMZ0POMVrhNWFKpOkEfV7UQ5Hh B3hu0y0tr8oFNFz6SeOdZG5LBHrmJ0AsGgqEod9deYx29lUNFaB262b8cGFSPRSwCcd7 AH4CDLgW0h74vOYYTr+g+O4fF+rSTMnMqDnPHBHcjlfU5xDX1eqHkHAwsWZDJHFQGLCH tJjt2TNfRo+4iGZzzxCRqt9H2Q+EKFoBOsWxz0i0cmN1oU+89j2TOURrI8BzTMFNroZx +FcA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696517394; x=1697122194; darn=m.gmane-mx.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=QsF+SCrrqU5t7L1Xcc8mN5yYQjbk4+6NGkFsLVCpCTc=; b=eNPOynnAmIK72uOIruQUUGP7Vba5tyalQNw5aJ/Txkj4lcezW5yKYrkORAWyDCUpdu 21RGk6BvCluvwJVRO33hnz8iKxA6Jo4oHw11XujWGYVtLHnm6tIaYNS+PtL2RCHIGp+b wki5DBRczWVk/tQCW/Zpms8Lil1IVNZZDVeBpZtHekd0YBSuZu2+G/NFzyF0AFqCGf2J WZyQCrTRGLwUVHLKNg1I6WAytIn12hBUsuXTYrKSYvBuI8VPPquNgOij2HHd1ZNCZrl0 MooUjRapFS75HxXh/BkQF1vQdJ3CC09S70yqigzuwN/H35ui/d5uX43pa2nGhTRJjysB /niw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696517394; x=1697122194; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-sender:mime-version:subject:references:in-reply-to :message-id:to:from:date:x-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=QsF+SCrrqU5t7L1Xcc8mN5yYQjbk4+6NGkFsLVCpCTc=; b=CtTggTaB5VGacW9yMH8JgADOn4x6enruXzREoPrJv7UOs/l+LVz9QE/KnjGibKVjKo Ul3PuqiZpImY4N+iWcpe3seQ1c25J9Dvq8Hft/zR9g9/meo8VlsanZ3Iotj+kyEB47xA LS8opS82hucpUAZ1avITsyC4WNDsOY0MGbif5qOPmEegAcgrZxdzJWcwJhfSwKbE3Vtg +yNc5TeE80g0wlhPy0aU12uDzyYZBoKK21IgpDWcnFI28l1olGd2U7KHuP1J8jWFrLHG kjZ1oxWPHOTjhZIe+qpw0wanMkgE6F0rGlmLBg8wc54MML315o Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOJu0YzmO+e64NnVnVcVOzWTaHXCfhziWv8CVve2H837gpKNCefoOGw1 8gVdd6xGk2ESvxYX/cMWMb0= X-Google-Smtp-Source: AGHT+IGWjjZEZJ8P4zfnXMZO/BdhVP+dolFA4EQ+vD+XhLflQF6ryzzAv8h71GQY+gHuZ0K0q2+m6g== X-Received: by 2002:a05:6870:ac09:b0:1d4:dce5:332e with SMTP id kw9-20020a056870ac0900b001d4dce5332emr6073355oab.51.1696517394519; Thu, 05 Oct 2023 07:49:54 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6871:88e:b0:1dd:6b48:3e2b with SMTP id r14-20020a056871088e00b001dd6b483e2bls986783oaq.2.-pod-prod-00-us; Thu, 05 Oct 2023 07:49:51 -0700 (PDT) X-Received: by 2002:a05:6870:1d0d:b0:1e2:16b:487d with SMTP id pa13-20020a0568701d0d00b001e2016b487dmr551162oab.5.1696517391309; Thu, 05 Oct 2023 07:49:51 -0700 (PDT) In-Reply-To: <875y3lnzho.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> X-Original-Sender: ffi.appdev-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:33158 Archived-At: ------=_Part_8986_1974259023.1696517390582 Content-Type: multipart/alternative; boundary="----=_Part_8987_2145685660.1696517390582" ------=_Part_8987_2145685660.1696517390582 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thursday, October 5, 2023 at 6:19:10=E2=80=AFAM UTC-4 Albert Krewinkel w= rote: jcr writes:=20 > Another approach is to use Lua's debug facilities to find the path to=20 > the script being executed, and add its directory to the Lua package=20 > path. This is the function I use:=20 >=20 > ```=20 > local function addMyDirToPath()=20 > local myFile =3D debug.getinfo(2, "S").source:sub(2)=20 > local myDir =3D myFile:match("(.*)/.*") or '.'=20 > package.path =3D ("%s/?.lua;%s"):format(myDir, package.path)=20 > end=20 > ```=20 That's elegant. Another way to get the value of `myDir` would be=20 local myDir =3D pandoc.path.directory(arg[0])=20 and should also work on all platforms. It relies on pandoc's built-in=20 path library and on a feature of the default lua interpreter, which=20 pandoc replicates for compatibility:=20 https://www.lua.org/manual/5.4/manual.html#7=20 I can't take credit for the elegance: that part comes from stackoverflow=20 (https://stackoverflow.com/a/23535333). The answer below it there does, in= =20 fact, suggest arg[0], but the elegant solution got more votes. I think I'll= =20 change my function to use arg[0] as you suggest. --=20 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 e= mail 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/9c7ac85d-ae26-41b2-941e-088bad98c353n%40googlegroups.com. ------=_Part_8987_2145685660.1696517390582 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thursday, October 5, 2023 at 6:19:10=E2=80= =AFAM UTC-4 Albert Krewinkel wrote:

jcr writes:

> Another approach is to use Lua's debug facilities to find the pa= th to
> the script being executed, and add its directory to the Lua pack= age
> path. This is the function I use:
>
> ```
> local function addMyDirToPath()
> local myFile =3D debug.getinfo(2, "S").source:sub(2)
> local myDir =3D myFile:match("(.*)/.*") or '.'
> package.path =3D ("%s/?.lua;%s"):format(myDir, package.path)
> end
> ```

That's elegant. Another way to get the value of `myDir` would be

local myDir =3D pandoc.path.directory(arg[0])

and should also work on all platforms. It relies on pandoc's built-in
path library and on a feature of the default lua interpreter, which
pandoc replicates for compatibility:
https://www.lua.org/manual/5.4/manual.html#7

I can't take credit for the elegan= ce: that part comes from stackoverflow (https://stackoverflow.com/a/2353533= 3). The answer below it there does, in fact, suggest arg[0], but the elegan= t solution got more votes. I think I'll change my function to use arg[0] as= you suggest.

--
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/9c7ac85d-ae26-41b2-941e-088bad98c353n%40googlegroups.= com.
------=_Part_8987_2145685660.1696517390582-- ------=_Part_8986_1974259023.1696517390582--