MrNil
|
  |
| Joined: 26 Apr 2014 |
| Total Posts: 352 |
|
|
| 27 Jun 2014 06:09 PM |
Do you hate only being able to return 1 value from a ModuleScript when requiring it? "Hate no more!" Here is something that will allow you to load all of the ModuleScript contents directly into the script requiring it, instead of 1 value:
--[[ModuleScript]]--
x,y,z=1,'hi',5
return setmetatable({},{ __call=function(t,t_) for i,v in pairs(getfenv())do t_[i]=v end end })
--[[Script]]-- require(ModuleScript)(getfenv())
print(x,y,z) --> 1 'hi' 5
I hope you find this useful. |
|
|
| Report Abuse |
|
|
|
| 27 Jun 2014 06:13 PM |
local content = {}
function content.isOPADamnIdiot() print("Yes") end
content.skillLevelOfOP = 0
return content
--script--
local stuff = require(randomModuleScript)
stuff.isOPADamnIdiot() > Yes
print(stuff.skillLevelOfOP) > 0 |
|
|
| Report Abuse |
|
|
MrNil
|
  |
| Joined: 26 Apr 2014 |
| Total Posts: 352 |
|
|
| 27 Jun 2014 06:18 PM |
| the point of this was so that you did not have to refer to a table to grab values |
|
|
| Report Abuse |
|
|
|
| 27 Jun 2014 06:26 PM |
| Why would you ever want to contaminate the global namespace with random variables that may or may not conflict with your own? |
|
|
| Report Abuse |
|
|
MrNil
|
  |
| Joined: 26 Apr 2014 |
| Total Posts: 352 |
|
|
| 27 Jun 2014 06:50 PM |
| Im just sharing it with you guys because i find it useful. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 27 Jun 2014 06:53 PM |
| I find that returning a table is more organized and you can tell what module your getting your stuff from. |
|
|
| Report Abuse |
|
|
HUBHUB13
|
  |
| Joined: 15 Oct 2010 |
| Total Posts: 36 |
|
|
| 27 Jun 2014 08:33 PM |
If worse comes to worst, then
return {a,b,c}
--script
local a,b,c=unpack(require(module)) |
|
|
| Report Abuse |
|
|
xSIXx
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 9202 |
|
|
| 27 Jun 2014 08:37 PM |
"the point of this was so that you did not have to refer to a table to grab values"
... but why not? |
|
|
| Report Abuse |
|
|
MrNil
|
  |
| Joined: 26 Apr 2014 |
| Total Posts: 352 |
|
|
| 27 Jun 2014 08:52 PM |
| @bove, At times i find it annoying to reference the returned table of the module repetitively. But thats just me |
|
|
| Report Abuse |
|
|