|
| 27 Dec 2013 07:14 PM |
My RBX.Lua script is giving me errors (obviously, why else would I be here?) and I can't figure out what's wrong, it's giving me a stupid stack overflow.
Script (no, it's not a local script though it shouldn't even matter) _G=setmetatable({},{ __index = function(self, index) return self[index:lower()] end, __call = function(self, ...) local arguments = {...} table.foreach(arguments, function(index, value) if type(getfenv(0)[value]) == "function" or type(getfenv(0)[value] == "thread" then getfenv(0)[value](self) end end) end })
Whenever I index it, it gives me it. Is there a reason? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Dec 2013 07:16 PM |
Yes, you are just re-invoking the __index metamethod every time.
return rawget(self, index:lower()) |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 27 Dec 2013 07:27 PM |
| Why are you using table.foreach instead of pairs? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Dec 2013 07:29 PM |
I don't know why he is, but it's deprecated. I guess it's faster to type? |
|
|
| Report Abuse |
|
|