Suppose I have the following structure on my computer:
directory
a.lua
subdirectory
b.lua
and this Lua code:
-- a.lua
foo = "bar"
-- b.lua
dofile("../a.lua")
print(foo)
If I now run lua b.lua
from directory, the relative path "../a.lua"
is relative to directory, and the interpreter complains that b.lua does not exist. If I run the same command from within subdirectory, then the relative path "../a.lua"
is relative to subdirectory, so it works.
My question: Why is it that relative paths are relative to where we execute the script, and how do I make it so that they are relative to where the script lives instead, like in the CJS require
?