lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 15/08/2019 22:52, Roberto Ierusalimschy wrote:
Apologies for resurrecting this months-old thread, but I would like to
chime in to support the idea of `require` returning a second result of the
path+filename where the module was found.

This is already implemented in Lua 5.4 alpha.
See https://www.lua.org/work/

-- Roberto



Is there a chance this enhancement will be backported to 5.3 branch?

It seems a very easy and useful change that doesn't break old code and doesn't cause "paradigm" shifts.

It would be nice to have a 5.3.6 having that (and usual pending bug fixes) until 5.4 is stable and finalized.

On a related note:

A long standing request from me for the interpreter on Windows was to have a way to know the exact /absolute/ filesystem location of a running script.

I know there are some tricks that do that, but they are not 100% reliable. In some edge cases you could end up with a /relative/ path, depending on how the interpreter was called.

I envision the interpreter defining a variable like say _CURRENT_SCRIPT_PATH and _CURRENT_SCRIPT_DIR that hold the relevant /absolute/ filesystem paths.

IIRC on Linux this is not so important/feasible, but on Windows there is an API call (I can't remember it now off the top of my head) to get the actual absolute path of the executable ("getModule"-something?!?) From that on the interpreter can deduce the actual path of the script and so on.

Thanks!

Lorenzo