20 posts
Posted 20 April 2016 - 03:20 AM
i just wanna be corrected if im wrong
setmetatable(os,{__index=getfenv()})
this does mean the os table can explore the enviorment right?
P.S i cant spell
3057 posts
Location
United States of America
Posted 20 April 2016 - 01:21 PM
No. It means os now contains everything in _G. For example, os.peripheral.wrap. Tables do not have environments.
12 posts
Posted 20 April 2016 - 04:26 PM
It means that if you try to index a value in os, if that index exists then it will return the value, otherwise it will try to find that value in getfenv() and return that.
You can think of it as
function lookup(k)
if os[k] then
return os[k]
else
return getfEnv()[k]
end
end
20 posts
Posted 20 April 2016 - 05:14 PM
okay thank you
7083 posts
Location
Tasmania (AU)
Posted 20 April 2016 - 11:53 PM
No. It means os now contains everything in _G. For example, os.peripheral.wrap. Tables do not have environments.
Two problems; one, at least within ComputerCraft, you would not expect getfenv() to return _G; and two, the command does not actually put the elements from getfenv() into os - it merely makes them available through it. pairs() for eg won't see them in there.