Skip to content

Scoped Module Imports#97

Open
jrmelsha wants to merge 2 commits intoluau-lang:masterfrom
jrmelsha:master
Open

Scoped Module Imports#97
jrmelsha wants to merge 2 commits intoluau-lang:masterfrom
jrmelsha:master

Conversation

@jrmelsha
Copy link

@jrmelsha jrmelsha commented Feb 1, 2025

@jackdotink
Copy link
Contributor

The type of imports used throughout this RFC are roblox's instance paths, which do not exist in Luau. Luau has imports with string requires.

@jrmelsha
Copy link
Author

jrmelsha commented Feb 2, 2025

The type of imports used throughout this RFC are roblox's instance paths, which do not exist in Luau. Luau has imports with string requires.

Thanks! - no problem, we can just substitute instance paths with string paths for the non-Roblox version.

@quantix-dev
Copy link

Great RFC. But, I believe that turning require into an explicit keyword would bloat luau's currently small number of keywords and confuse the matter where it was once a function. Instead, I think adding destructuring to objects would preserve the simplicity of require while offering cleaner module imports.

@aatxe aatxe mentioned this pull request Feb 24, 2025
@ishtar112
Copy link

In my eyes, this problem is pretty eloquently solved with user-defined aliases. To use your example, though user-defined aliases are not yet available in ROBLOX, we can imagine:

local Pet = require("@items/Pet")
local Currency = require("@items/Currency")

which is comparatively more verbose than your proposal but does indeed do away with the majority of the boilerplate, and it does so without such convoluted and controversial changes to the language.

In fact, this problem has always been solved quite well by simply using more variables:

local Items = game.ReplicatedStorage.Library.Items
local Pet, Currency = require(Items.Pet), require(Items.Currency)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants