From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/33151 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: Wed, 4 Oct 2023 06:54:07 -0700 (PDT) Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_5974_1851067558.1696427647259" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5521"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDQLFNXWVILBBAG56WUAMGQE5OF2G4A-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Oct 04 15:54:13 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f57.google.com ([209.85.161.57]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qo2KL-00015u-6A for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 04 Oct 2023 15:54:13 +0200 Original-Received: by mail-oo1-f57.google.com with SMTP id 006d021491bc7-57de452a64fsf2218573eaf.2 for ; Wed, 04 Oct 2023 06:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1696427652; x=1697032452; 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=aJEh5KQXEkZ9+/hqVXhL/QdR1KusZmTaDXxmTQ3Z44I=; b=eEQwWtGx9A4qu74YUC0TyV6L5GQBYRnYrRBp1a34+JUXCj2jQmUcWflDLm5Zo/6abY fvf0SnUO7t08VI4R6YEoM5w/Wc1y3yy8ULqA3PD/0njNtZC/nlyJLy5E5k6itf+MmvuN jTOcLo5invwkKDfgL3RiSjcVqNXkczywfHGeUqsT6K9nkafaKcaYaSM6rg5K0AxhqYv2 vXeX8KfLkzvfn5SogObdhG48YfE3fJD/Ko2DecvCR6oEd5UCbSZT2T7hXnlASdnDX0bp lSeRV7R9HhbheD+cDm30hy62LMz/RgNSl/lUoFiYpC2Q7cvgFTxxoLerRVe4LRk76+u0 OjEg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696427652; x=1697032452; 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=aJEh5KQXEkZ9+/hqVXhL/QdR1KusZmTaDXxmTQ3Z44I=; b=FXc07pQIffTvQLzve4Z/Rkomq8lprKgeOyvZcDm4A8w/S+DK9rqscB9soK/gIIxN9J kDd28KyuaPWPd+P1mwriXwowuEwtJZzlLHelNOsxWpw7Eo+imBIuwfV7nNQi19vtIUyj QhwdPB5NwxLR4xwqEm+IqHPeHuH2Fj3lpEtg2KZ+cb6MCxS/IeHcyuq4HErh0pGk1fim 48SqBX/pLfZGURTTWFq845wkqyst/k1CiCSfHFTkALR+ieOY3IYDLvSkvMQnvtgxqumx ssRk9MJ1NqwNFmux/BbrQ8in66OqtLBrhYhLrFYtDLviUyH0mfN5mdwC3SFBMS7436Gn 7woA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696427652; x=1697032452; 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=aJEh5KQXEkZ9+/hqVXhL/QdR1KusZmTaDXxmTQ3Z44I=; b=ogO3JP721GFhm2WAgg4G73yDWW/3io3cmxJQwpARBbsQa4h0jSagnQWo+2ksPlbHpg uNULLWZYf1jGLjEgglMl6UazX0iC5fXevzhe4jnexc7Yq2cwThn6nmXhOxAZ4BvNKfrM vyex+n2FjiyO/f3dP9I2Ah0P4ha9HI2SEYBQ33t2c6RkDIJR6G4rItDvwrhvCb31IFcd U/azbJyOLFfJATkaljkPSZUIobB3cqRfz5cikXOx6ilI7mUA3UwQZib/01p37dqGrVVs y0CrJ23avxoqsHbS6+7vOfNwPR+g1hKsw5NtAf4qU9/xPTZ5E0 Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOJu0YyDnwkXW1ynZRBf+DnJUOBU9HM/LiGBLIQnp05mkRnwXM/jl9Vx KwcnE5e29AnlC0f4eoNs5uk= X-Google-Smtp-Source: AGHT+IHy2RZbagIvEOxdnBkt1fGyCUaC0I8SRMV2Cwt3928+9XZw+emhmWwHAEdkR792Fekc27bnAg== X-Received: by 2002:a4a:ea39:0:b0:56e:9e98:2cfd with SMTP id y25-20020a4aea39000000b0056e9e982cfdmr2387319ood.2.1696427652085; Wed, 04 Oct 2023 06:54:12 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a4a:4f15:0:b0:57b:6325:be05 with SMTP id c21-20020a4a4f15000000b0057b6325be05ls2570247oob.1.-pod-prod-02-us; Wed, 04 Oct 2023 06:54:08 -0700 (PDT) X-Received: by 2002:a9d:7dcf:0:b0:6b8:6cec:b73e with SMTP id k15-20020a9d7dcf000000b006b86cecb73emr620009otn.5.1696427647960; Wed, 04 Oct 2023 06:54:07 -0700 (PDT) In-Reply-To: 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:33151 Archived-At: ------=_Part_5974_1851067558.1696427647259 Content-Type: multipart/alternative; boundary="----=_Part_5975_1388386542.1696427647259" ------=_Part_5975_1388386542.1696427647259 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Another approach is to use Lua's debug facilities to find the path to the= =20 script being executed, and add its directory to the Lua package path. This= =20 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 ``` To adapt this to your directory structure, just change the format string on= =20 the third line of the function to ` "%s/../library/?.lua;%s"`. On Tuesday, October 3, 2023 at 12:50:39=E2=80=AFPM UTC-4 Bastien DUMONT wro= te: > The argument of require() is not a path, but a string that is passed to a= =20 > template. The template is composed of semi-colon separated strings where = ?=20 > is stands for the argument of require() (after all . have been replaced= =20 > with /). For instance, if the template is: > > ./?.lua;/usr/local/share/lua/5.4/?.lua > > and you pass 'library.library' to it, Lua will search in=20 > ./library/library.lua and /usr/local/share/lua/5.4/library/library.lua > > The path is controlled by environment variables. In your case, if all=20 > loaded files are in the ../library directory, I would advise to call your= =20 > script with: > > LUA_PATH=3D'../library/?.lua' pandoc-lua script.lua > > and to write in inner/script.lua: > > library =3D require("library") > > Of course, you can also set the path to '../?.lua;./?.lua' if you want to= =20 > be able to load files from the current directory and to write explicitely= =20 > the path to library.lua as library.library! > > Le Tuesday 03 October 2023 =C3=A0 09:17:04AM, ch_...-S0/GAf8tV78@public.gmane.org a =C3=A9crit = : > > I have the following file structure: > >=20 > > inner/script.lua > > library/library.lua > >=20 > > I try to load the library from within the script > >=20 > > library =3D require("../library/library.lua") > >=20 > > but get an error when running inside inner: pandoc lua script.lua > >=20 > > Error running Lua: > > script.lua:1: module '../library/library.lua' not found: > > no field package.preload['../library/library.lua'] > > no file '/usr/local/share/lua/5.4////library/library/lua.lua' > > no file '/usr/local/share/lua/5.4////library/library/lua/init.lua' > > no file '/usr/local/lib/lua/5.4////library/library/lua.lua' > > no file '/usr/local/lib/lua/5.4////library/library/lua/init.lua' > > no file './///library/library/lua.lua' > > no file './///library/library/lua/init.lua' > > no file '/usr/local/lib/lua/5.4////library/library/lua.so' > > no file '/usr/local/lib/lua/5.4/loadall.so' > > no file './///library/library/lua.so' > > no file '/usr/local/lib/lua/5.4/.so' > > no file '/usr/local/lib/lua/5.4/loadall.so' > > no file './.so' > > stack traceback: > > script.lua:1: in main chunk > >=20 > > -- > > You received this message because you are subscribed to the Google Grou= ps > > "pandoc-discuss" group. > > To unsubscribe from this group and stop receiving emails from it, send= =20 > an email > > to [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2] > https://groups.google.com/d/msgid/ > > pandoc-discuss/ee1ceb10-3318-48d0-ae1a-0ca538a3cdc9n%40googlegroups.com= . > >=20 > > References: > >=20 > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2]=20 > https://groups.google.com/d/msgid/pandoc-discuss/ee1ceb10-3318-48d0-ae1a-= 0ca538a3cdc9n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter > > --=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/d94cef59-9869-4376-9d36-b38cab195025n%40googlegroups.com. ------=_Part_5975_1388386542.1696427647259 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Another approach is to use Lua's debug facilities to find the path to = the script being executed, and add its directory to the Lua package path. T= his is the function I use:
```
local function addMyDirT= oPath()
=C2=A0 local myFile =3D debug.getinfo(2, "S").source:sub(2)=C2=A0 local myDir =3D myFile:match("(.*)/.*") or '.'
=C2=A0 packag= e.path =3D ("%s/?.lua;%s"):format(myDir, package.path)
end
=
```
To adapt this to your directory structure, just ch= ange the format string on the third line of the function to ` "%s/../librar= y/?.lua;%s"`.
On Tuesday, October 3, 2023 at 12:50:39=E2=80=AFPM UTC-4 Bastien = DUMONT wrote:
The argument of require() is not a path, but a string that is passed to a = template. The template is composed of semi-colon separated strings where ? = is stands for the argument of require() (after all . have been replaced wit= h /). For instance, if the template is:

./?.lua;/usr/local/share/lua/5.4/?.lua

and you pass 'library.library' to it, Lua will search in ./libr= ary/library.lua and /usr/local/share/lua/5.4/library/library.lua

The path is controlled by environment variables. In your case, if all l= oaded files are in the ../library directory, I would advise to call your sc= ript with:

LUA_PATH=3D'../library/?.lua' pandoc-lua script.lua

and to write in inner/script.lua:

library =3D require("library")

Of course, you can also set the path to '../?.lua;./?.lua' if y= ou want to be able to load files from the current directory and to write ex= plicitely the path to library.lua as library.library!

Le Tuesday 03 October 2023 =C3=A0 09:17:04AM, ch_...-S0/GAf8tV78@public.gmane.org a =C3=A9crit :
> I have the following file structure:
>=20
> inner/script.lua
> library/library.lua
>=20
> I try to load the library from within the script
>=20
> library =3D require("../library/library.lua")
>=20
> but get an error when running inside inner: pandoc lua script.lua
>=20
> Error running Lua:
> script.lua:1: module '../library/library.lua' not found:
> no field package.preload['../library/library.lua']
> no file '/usr/local/share/lua/5.4////library/library/lua.lua&#= 39;
> no file '/usr/local/share/lua/5.4////library/library/lua/init.= lua'
> no file '/usr/local/lib/lua/5.4////library/library/lua.lua'= ;
> no file '/usr/local/lib/lua/5.4////library/library/lua/init.lu= a'
> no file './///library/library/lua.lua'
> no file './///library/library/lua/init.lua'
> no file '/usr/local/lib/lua/5.4////library/library/lua.so'
> no file '/usr/local/lib/lua/5.4/loadall.so'
> no file './///library/library/lua.so'
> no file '/usr/local/lib/lua/5.4/.so'
> no file '/usr/local/lib/lua/5.4/loadall.so'
> no file './.so'
> stack traceback:
> script.lua:1: in main chunk
>=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 email
> to [1]pandoc-discus...@= googlegroups.com.
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/ee1ceb10-3318-48d0-ae1a-0ca538a3cdc9n%40googlegroups.com.
>=20
> References:
>=20
> [1] mailto:pandoc-discu= s...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups= .google.com/d/msgid/pandoc-discuss/ee1ceb10-3318-48d0-ae1a-0ca538a3cdc9n%40= googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter

--
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/d94cef59-9869-4376-9d36-b38cab195025n%40googlegroups.= com.
------=_Part_5975_1388386542.1696427647259-- ------=_Part_5974_1851067558.1696427647259--