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

Feature request: find out if the script is the main script #279

Open
lammermann opened this issue Dec 2, 2024 · 3 comments
Open

Feature request: find out if the script is the main script #279

lammermann opened this issue Dec 2, 2024 · 3 comments
Labels
enhancement New feature or request pending / needs design Awaiting design and/or implementation discussion and decisions

Comments

@lammermann
Copy link

In python you can do something like this

...
if __main__:
    main()

It would be pretty handy for my use case to have something similar in lune, too. I often like my scripts to be usable as scripts, but to be able to require them as a module in other situations (e.g. unit testing). Maybe the process library would be a good place for this. Than I could have at the end of my scripts something like this:

local process = require("@lune/process")
local M = {}
...
if process.is_main then
  M.main()
else
  return M
end

Would you consider adding this feature?

Btw. Thanks for lune. It's a great tool

@filiptibell filiptibell added enhancement New feature or request pending / needs design Awaiting design and/or implementation discussion and decisions labels Dec 18, 2024
@CompeyDev
Copy link
Contributor

Seems a bit inappropriate to put it in the process built-in, since it does not have much to do with describing the lune process IMO, but more of describing the environment of the script being executed... maybe we include it as a global of some kind?

@lammermann
Copy link
Author

A global sounds good to me. Maybe even in the same way as python does it. It seems unlikely anybody using __main__ in an existing script till now.

@CleverSource
Copy link

CleverSource commented Dec 23, 2024

This could be done through the script global if partial support for it were added. I use red-blox/Util's Future implementation and partial support where script.Parent goes up the file directory could make Roblox-made libraries more plug & play in the Luau ecosystem that Lune is providing.

This could be extended to have script.__main__ or script.is_main as well. It seems like a decent design structure to me and will be familiar with those coming from Roblox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pending / needs design Awaiting design and/or implementation discussion and decisions
Projects
None yet
Development

No branches or pull requests

4 participants