| |
|
»
»
|
|
| |
|
|
|
|
|
| 16 Jan 2015 09:24 PM |
for i,v in pairs(getfenv(0)) do print(i,v) end
Blank output
getfenv(0).print("Hello!")
Hello!
Someone wanna explain this to me? |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 16 Jan 2015 09:26 PM |
In ROBLOX, getfenv(0) returns this:
{ script = REFERENCE_TO_CURRENT_SCRIPT }
But this environment has its __index metamethod set to the REAL global environment, which has things like print. This is to prevent hackers from modifying print in one script and having it influence the other scripts.
If you want to rewrite print just do:
print = function(...) -- etc end
And it will work just fine. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:29 PM |
| @ser Actually no, I need a table full of all the variables like print, and I would prefer not to have to hardcode them all in. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 16 Jan 2015 09:36 PM |
I wrote a program which brute forces every variable in the global environment. Here's the result:
local global_variables = { "UDim2", "setfenv", "LoadLibrary", "Stats", "tick", "Region3", "Spawn", "stats", "next", "print", "Delay", "Workspace", "ElapsedTime", "workspace", "pairs", "load", "elapsedTime", "os", "ypcall", "CFrame", "assert", "newproxy", "ipairs", "version", "game", "rawset", "shared", "time", "Region3int16", "_VERSION", "Version", "table", "Wait", "pcall", "tostring", "settings", "loadstring", "Color3", "CellId", "Vector2", "collectgarbage", "UserSettings", "_G", "delay", "UDim", "Game", "Ray", "error", "spawn", "Instance", "wait", "Vector2int16", "Faces", "math", "setmetatable", "select", "xpcall", "dofile", "loadfile", "coroutine", "getmetatable", "type", "rawget", "DebuggerManager", "Enum", "unpack", "BrickColor", "rawequal", "Axes", "string", "Vector3", "require", "PluginManager", "getfenv", "tonumber", "printidentity", "warn", "Vector3int16", "gcinfo" } |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:39 PM |
| @Ser That'll have to do, but if you find a way without hardcoding, please let me know. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
| |
|
|
| 16 Jan 2015 09:42 PM |
@Ser So should this work?
local module = {}
module.Setup = function() local global_variables = setmetatable({ "UDim2", "setfenv", "LoadLibrary", "Stats", "tick", "Region3", "Spawn", "stats", "next", "print", "Delay", "Workspace", "ElapsedTime", "workspace", "pairs", "load", "elapsedTime", "os", "ypcall", "CFrame", "assert", "newproxy", "ipairs", "version", "game", "rawset", "shared", "time", "Region3int16", "_VERSION", "Version", "table", "Wait", "pcall", "tostring", "settings", "loadstring", "Color3", "CellId", "Vector2", "collectgarbage", "UserSettings", "_G", "delay", "UDim", "Game", "Ray", "error", "spawn", "Instance", "wait", "Vector2int16", "Faces", "math", "setmetatable", "select", "xpcall", "dofile", "loadfile", "coroutine", "getmetatable", "type", "rawget", "DebuggerManager", "Enum", "unpack", "BrickColor", "rawequal", "Axes", "string", "Vector3", "require", "PluginManager", "getfenv", "tonumber", "printidentity", "warn", "Vector3int16", "gcinfo" }, _G) for i,v in pairs(getfenv(0)) do rawset(_G, i, v) end setfenv(0, setmetatable({}, { __index = global_variables, __newindex = function(t, k, v) rawset(_G, k, v) end, __metatable = "This metatable is locked!" })) end
return module |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 16 Jan 2015 09:44 PM |
| No, but I'm not sure what you're trying to accomplish. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:48 PM |
You know how _G used to be? I'm trying to accomplish that. So like, one script could say
x = 5
and another could go
repeat wait() until x print(x)
--5
What's wrong with my script? |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 16 Jan 2015 09:53 PM |
To bad roblox ruined _G
in normal lua
for _, v in next, _G do print(_, v) end --[[> string table: 0x1055a0 xpcall function: 0x104fa8 package table: 0x105a58 tostring function: 0x104f00 print function: 0x104fe0 os table: 0x1071e0 unpack function: 0x104f70 require function: 0x105f18 getfenv function: 0x104c40 setmetatable function: 0x104e88 next function: 0x104d28 assert function: 0x104b90 tonumber function: 0x104ec8 io table: 0x1069d8 rawequal function: 0x105018 collectgarbage function: 0x104bc8 getmetatable function: 0x104da0 module function: 0x105cb0 rawset function: 0x105088 math table: 0x107de0 debug table: 0x108780 pcall function: 0x104d60 table table: 0x1050f8 newproxy function: 0x1056b0 type function: 0x104f38 coroutine table: 0x105718 _G table: 0x104460 select function: 0x104e18 gcinfo function: 0x104c08 pairs function: 0x104a48 rawget function: 0x105050 loadstring function: 0x104cf0 ipairs function: 0x1049e8 _VERSION Lua 5.1 dofile function: 0x104488 setfenv function: 0x104e50 load function: 0x104cb8 error function: 0x104c80 loadfile function: 0x104de0 ]] |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:54 PM |
| I mean, obviously I'm going to fix the globals table so that each part actually equals the proper function, but other than that what's wrong? |
|
|
| Report Abuse |
|
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|