This got debunked by @Anaminus . It's not possible, so ignore.
So, this is simply a thought … but I’m curious on what others think.
Currently, I am creating a game in which I’m dividing pieces of the code into ModuleScripts. However, I still need the ModuleScripts to contain the Environment of it’s caller. My solution is to return a function in which the requiring Script will use setfenv to “merge” the Environment. Here’s a sloppy example below:
ServerScript requiring our Module
local RequiredModule = require(script:WaitForChild("AModuleAaay"), {
"This table contains something I want to pass",
"Oh look, another thing I wanna pass",
true
}, true, false, ...)
ModuleScript being required by ServerScript
local PassedArguments = {...} -- command line anyone? :))
-- do stuff with PassedArguments!!!.... aay
My reasoning for such implementation is simple:
Previously, I requested the implementation of a SharedModule, and learned of the many reasons why such Module shouldn’t exist. Being a wee more seasoned, I now understand the reasoning for not doing such hacks … Modules are supposed to be plug and play, right? So, instead of attempting to unify a ModuleScript into the requiring Script’s environment, I propose we add the ability to pass arguments to the ModuleScript using require. As a developer, I believe this would significantly help developers in making code modular, as we would be able to pass variables we need through the function without having to do ugly return function hacks. So yea … thats my idea.
Disclaimer: this was written at 6:10AM (and I sleep in the day, and haven’t gone to bed yet …) and I am exausted. I probably did a horrible job pitching this idea, and expect to see replies to such horrible pitch. If you have questions, I’ll do my best to answer them after a good days nights sleep!