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. This is the function I use: ``` local function addMyDirToPath() local myFile = debug.getinfo(2, "S").source:sub(2) local myDir = myFile:match("(.*)/.*") or '.' package.path = ("%s/?.lua;%s"):format(myDir, package.path) end ``` To adapt this to your directory structure, just change the format string on the third line of the function to ` "%s/../library/?.lua;%s"`. On Tuesday, October 3, 2023 at 12:50:39 PM 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 > 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 > ./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 > loaded files are in the ../library directory, I would advise to call your > script with: > > LUA_PATH='../library/?.lua' pandoc-lua script.lua > > and to write in inner/script.lua: > > library = require("library") > > Of course, you can also set the path to '../?.lua;./?.lua' if you want to > be able to load files from the current directory and to write explicitely > the path to library.lua as library.library! > > Le Tuesday 03 October 2023 à 09:17:04AM, ch_...-S0/GAf8tV78@public.gmane.org a écrit : > > I have the following file structure: > > > > inner/script.lua > > library/library.lua > > > > I try to load the library from within the script > > > > library = require("../library/library.lua") > > > > but get an error when running inside inner: pandoc lua script.lua > > > > 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 > > > > -- > > 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...-/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. > > > > References: > > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2] > https://groups.google.com/d/msgid/pandoc-discuss/ee1ceb10-3318-48d0-ae1a-0ca538a3cdc9n%40googlegroups.com?utm_medium=email&utm_source=footer > > -- 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/d94cef59-9869-4376-9d36-b38cab195025n%40googlegroups.com.