1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 08 Sep 2013 08:07 PM |
| getfenv(0) is completely empty. If I change the function environment then all of the global functions are unrecognized, and I don't know how to include all of the global functions in the new environment because I don't know where they are. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 08 Sep 2013 08:25 PM |
| `getfenv(0)` is empty to those who don't look past what can be seen normally. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 08 Sep 2013 08:27 PM |
^
Couldn't have said it better myself. |
|
|
| Report Abuse |
|
|
dekkonot
|
  |
| Joined: 22 Dec 2010 |
| Total Posts: 6685 |
|
|
| 08 Sep 2013 08:28 PM |
^But Roblox is an engine, not a game.
~ Linguam latinam est optimum ~ |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 08 Sep 2013 08:28 PM |
global functions are storted in getmetatable(getfenv(0)).__index but getfenv(0) metatable is locked, derfore u cant access it. |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 08 Sep 2013 08:37 PM |
I cheated.
do local g=setmetatable({},{__index=function(t,k)return rawget(t,k)or loadstring('return '..k)()end}) setfenv(1,setmetatable({print=print},{ __newindex=function(t,k,v) print('set '..k..' to '..tostring(v)) g[k]=v end, __index=function(t,k) print('get '..k) return g[k] end } )) end ----------------------------------- |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 09 Sep 2013 01:41 PM |
Try _G
Lua stores the environment in` _G`, so `_G.print` should equal `print` |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 09 Sep 2013 02:34 PM |
| You try _G. It's empty. All it has is gloo GUI Library. Shared is empty. getfenv(0) is empty. oxcool already explained where all of the globals are. |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 09 Sep 2013 04:06 PM |
I made my method considerably shorter:
setfenv(1,setmetatable({},{ __newindex=function(t,k,v) print('set '..k..' to '..tostring(v)) rawset(t,k,v) end, __index=function(t,k) print('get '..k) return rawget(t,k)or loadstring('return '..k)() end })) |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 09 Sep 2013 04:41 PM |
It seems like jobro put way too much code into making 2+2=5. this is all I had to do to make that happen:
setfenv(1,setmetatable({print=print},{ __newindex=function(t,k,v) rawset(t,k,type(v)=='number'and setmetatable({v},{ __add=function(a,b) return a[1]+b[1]+1 end })or v) end })) a=2 b=2 print(a+b) |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 09 Sep 2013 04:55 PM |
actually my new method doesn't work quite perfectly
but with my amendment applied to it it does:
setfenv(1,setmetatable({},{ __newindex=function(t,k,v) print('set '..k..' to '..tostring(v)) getfenv()[k]=v end, __index=function(t,k) print('get '..k) return getfenv()[k]or loadstring('return '..k)() end })); |
|
|
| Report Abuse |
|
|