Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Sandboxing local variables using setfenv?

Asked by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

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

Log in to vote
1
Answered by
digpoe 65 Badge of Merit
10 years ago

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

0
Isn't the debug library only Lua 5.2? 1waffle1 2908 — 10y
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. MessorAdmin 598 — 9y
Ad

Answer this question