Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Sandboxing local variables using setfenv?

This prints 5 and then 6. It's supposed to add 1 to any variable set, so a should be 6 and b should be 6, but __newindex doesn't affect a because it was declared locally. Is there any way to filter local variables?

do
	local e={print=print}
	setfenv(1,setmetatable({},{
		__index=function(t,k)
			return e[k]or loadstring('return '..k)()
		end,
		__newindex=function(t,k,v)
			e[k]=v+1
		end
	}))
end

local a=5
print(a)

b=5
print(b)

1 answer

Local variables can't be found unless you're using the debug library; here But it's useless in ROBLOX.

2 comments

0

Isn't the debug library only Lua 5.2?

0

There are other ways to sandbox, (Obv), I have seen a few.. My friend is INSANE at sandboxing.. If you still need help ask LordRevorius and tell him I sent you.

This discussion is preserved as it was. New answers, comments, and votes are closed.