On Thursday, October 5, 2023 at 6:19:10 AM UTC-4 Albert Krewinkel wrote:

jcr writes:

> 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
> ```

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

local myDir = 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 elegance: that part comes from stackoverflow (https://stackoverflow.com/a/23535333). The answer below it there does, in fact, suggest arg[0], but the elegant 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 "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-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.