Skip to content

Commit

Permalink
Make all standalone modules pass-through Wax's env
Browse files Browse the repository at this point in the history
  • Loading branch information
regginator committed Oct 5, 2023
1 parent 100167b commit d5ba564
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ SUBCOMMANDS:

## Runtime Spec Details

* Like a model on Roblox's [Developer Marketplace](https://create.roblox.com/marketplace/models), a ModuleScript under the model root named (exactly) "MainModule" will automatically run at init and pass its return through the **real** script
* If there's only 1 instance directly under the model root and it's a `ModuleScript`, that module will automatically run at init and pass its return through the **real** script, just as expected with normal module behavior. Additionally, like a model on Roblox's [Developer Marketplace](https://create.roblox.com/marketplace/models), a `ModuleScript` under the model root named (exactly) "MainModule" will also have the same functionality, even if there is more than 1 instance directly under the model root
* The real `getfenv`/`setfenv` functions are not overriden by global flattening whatsoever, so by using for example `getfenv(0)` it will return the actual root function environment of the script. *Just know that its behavior isn't modified whatsoever for virtual closures!*
* Instance `ClassName`s that will bundle:
* `Folder`
Expand Down
2 changes: 1 addition & 1 deletion default.project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "MainModule",
"name": "Wax",
"tree": {
"$path": "lune/wax.luau",

Expand Down
17 changes: 12 additions & 5 deletions lune/lib/data/Template.luau
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,18 @@ end
-- If there's a "MainModule" top-level modulescript, we'll return it from the output's closure directly
do
local MainModule
for _, Ref in next, RealObjectRoot:GetChildren() do
if Ref.ClassName == "ModuleScript" and Ref.Name == "MainModule" then
MainModule = Ref
break
local MainModule
local RealObjectRootChildren = RealObjectRoot:GetChildren()
-- Doesn't need to be named "MainModule" if there's just 1 root obj and it's a ModuleScript
if #RealObjectRootChildren == 1 and RealObjectRootChildren[1].ClassName == "ModuleScript" then
MainModule = RealObjectRootChildren[1]
else
for _, Ref in next, RealObjectRootChildren do
if Ref.ClassName == "ModuleScript" and Ref.Name == "MainModule" then
MainModule = Ref
break
end
end
end
Expand Down

0 comments on commit d5ba564

Please sign in to comment.