Copying standard tables (_G/_ENV)

Started by hugeblank, Oct 19, 2018, 06:24 am

Previous topic - Next topic


Right, so I'm perfectly aware that _G contains itself, as does _ENV. But which one would I want to copy in the case that I want to set a functions environment using, say, a modified fs API? And how would I go about doing it so that the environment above it isn't affected? Is it as simple as a shallow copy?
"inspirational quote"
- Motivational Speaker

Also the first user to set the theme to "Curve2" as their default.


When making a new environment you can use metatables to skip the copy part (reference implementation), that way your new environment only contains what it changed from the previous. If you want to sandbox, however, you will need to copy the table contents.