Skip to content

Fix functions returned from luau.load not being able to call require#301

Merged
vrn-sn merged 5 commits intoluau-lang:primaryfrom
green-real:luau-load-require-fix
Jun 3, 2025
Merged

Fix functions returned from luau.load not being able to call require#301
vrn-sn merged 5 commits intoluau-lang:primaryfrom
green-real:luau-load-require-fix

Conversation

@green-real
Copy link
Copy Markdown
Contributor

luau.load currently doesn't pass a valid chunkname to luau_load that can be used to handle calls to require. This PR fixes that by retrieving the source path of the caller using lua_getinfo. If no second argument was passed and if the source path of the caller couldn't be retrieved, luau.load will throw an error.

This PR also changes luau.load so that the second argument is considered a path, relative to the current working directory. This path is converted to a proper chunk name by inserting '@' at the start.

@aatxe aatxe requested a review from vrn-sn May 29, 2025 21:05
@green-real green-real force-pushed the luau-load-require-fix branch from ba87d27 to 6976c13 Compare May 30, 2025 15:37
Copy link
Copy Markdown
Member

@vrn-sn vrn-sn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to discuss more, left some comments.

@vrn-sn vrn-sn merged commit af141e1 into luau-lang:primary Jun 3, 2025
7 checks passed
@green-real green-real deleted the luau-load-require-fix branch June 3, 2025 00:44
@vrn-sn vrn-sn mentioned this pull request Jun 5, 2025
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.

2 participants