Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

... is not populated when tl run loads a Lua module #689

Closed
fperrad opened this issue Aug 21, 2023 · 2 comments · Fixed by #693
Closed

... is not populated when tl run loads a Lua module #689

fperrad opened this issue Aug 21, 2023 · 2 comments · Fixed by #693
Labels
bug Something isn't working

Comments

@fperrad
Copy link
Contributor

fperrad commented Aug 21, 2023

$ cat ld.lua 
require'foo'
print('Done')
$ cat foo.lua 
print(...)
$ lua ld.lua 
foo	./foo.lua
Done
$ ./tl run ld.lua 

Done
@hishamhm
Copy link
Member

hishamhm commented Sep 4, 2023

@fperrad Is this behavior documented? I tried to find it in the Lua manual but I must have missed it. I am in favor of implementing, but ideally I would like to follow the documentation to ensure I got the behavior right.

@hishamhm hishamhm added the bug Something isn't working label Sep 4, 2023
hishamhm added a commit that referenced this issue Sep 4, 2023
@fperrad
Copy link
Contributor Author

fperrad commented Sep 5, 2023

quoted from https://www.lua.org/manual/5.4/manual.html#pdf-require

Once a loader is found, require calls the loader with two arguments: modname and an extra value, a loader data, also returned by the searcher. The loader data can be any value useful to the module; for the default searchers, it indicates where the loader was found. (For instance, if the loader came from a file, this extra value is the file path.)

hishamhm added a commit that referenced this issue Sep 5, 2023
Instead of hardcoding the arguments within the loader, pass them
through the searcher, as specified by the documented behavior:

#689 (comment)

> quoted from https://www.lua.org/manual/5.4/manual.html#pdf-require
>
>> Once a loader is found, require calls the loader with two arguments:
>> modname and an extra value, a loader data, also returned by the
>> searcher. The loader data can be any value useful to the module;
>> for the default searchers, it indicates where the loader was found.
>> (For instance, if the loader came from a file, this extra value is
>> the file path.)

Thanks @fperrad for the research!
hishamhm added a commit that referenced this issue Sep 5, 2023
hishamhm added a commit that referenced this issue Sep 5, 2023
Instead of hardcoding the arguments within the loader, pass them
through the searcher, as specified by the documented behavior:

#689 (comment)

> quoted from https://www.lua.org/manual/5.4/manual.html#pdf-require
>
>> Once a loader is found, require calls the loader with two arguments:
>> modname and an extra value, a loader data, also returned by the
>> searcher. The loader data can be any value useful to the module;
>> for the default searchers, it indicates where the loader was found.
>> (For instance, if the loader came from a file, this extra value is
>> the file path.)

Thanks @fperrad for the research!
hishamhm added a commit that referenced this issue Sep 5, 2023
Instead of hardcoding the arguments within the loader, pass them
through the searcher, as specified by the documented behavior:

#689 (comment)

> quoted from https://www.lua.org/manual/5.4/manual.html#pdf-require
>
>> Once a loader is found, require calls the loader with two arguments:
>> modname and an extra value, a loader data, also returned by the
>> searcher. The loader data can be any value useful to the module;
>> for the default searchers, it indicates where the loader was found.
>> (For instance, if the loader came from a file, this extra value is
>> the file path.)

Thanks @fperrad for the research!
hishamhm added a commit that referenced this issue Sep 5, 2023
* fix: populate `...` for required modules

Fixes #689.

* adjust code to more closely match documented semantics

Instead of hardcoding the arguments within the loader, pass them
through the searcher, as specified by the documented behavior:

#689 (comment)

> quoted from https://www.lua.org/manual/5.4/manual.html#pdf-require
>
>> Once a loader is found, require calls the loader with two arguments:
>> modname and an extra value, a loader data, also returned by the
>> searcher. The loader data can be any value useful to the module;
>> for the default searchers, it indicates where the loader was found.
>> (For instance, if the loader came from a file, this extra value is
>> the file path.)

Thanks @fperrad for the research!

* loader args: provide consistent behavior across Lua versions

This implements a compromise solution that allows Teal modules
to always get both arguments, even in Lua 5.1 based systems
(this should be harmless for modules which don't expect a second
argument there), without hardcoding `loader_data`, just in case
the user is on an environment that runs a patched `require` for
debug reasons or something.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants