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

Why is this printing things?

Asked by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
7 years ago
Edited 7 years ago
setfenv(function()end,setmetatable({},{__index=print}))()

This should not print anything, but the output says

table: 1CF65F98 script

table: 1CF65F98 script

similarly, this should error "lag" but something mysterious causes otherwise

local c,tick,error=tick(),tick,error
setfenv(1,setmetatable({},{
    __index=function(t,k)
        --print(t,k)
        return rawget(t,k)
    end})
);
(function(f)
    return f(f)
end)(function(f)
    if tick()-c>1 then
        error("lag")
    end 
    return f(f)
end)

This only happens in Roblox. What is going on?

0
Lol you are soo advanced in scripting, I feel like no one would know how to help you :P FiredDusk 1466 — 7y
0
This is easy to understand. Link150 1355 — 7y

1 answer

Log in to vote
1
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

This happened to me a couple of months ago, I'm not entirely sure why it's exactly happening but here were my conclusions:

local print = print

local function func()
    print("Blah")
    print("kah")
    local y = 3
end

setfenv(func, setmetatable({ script = 123 }, {
    __index = function(self, key)
        -- getfenv(0) == getfenv(1) == getfenv(3)
        -- getfenv(2) == getfenv(func)
        print("Current env", getfenv(1), rawget(getfenv(1), "script"))
        print("Caller env", getfenv(2), rawget(getfenv(2), "script"))
        print("Caller of Caller env", getfenv(3), rawget(getfenv(3), "script"))
    end
}))

print("func Function Environment", getfenv(func))
print("Global Environment", getfenv(0))
print("Enclosing Function Environment", getfenv(1)) -- should be the global environment

func()

It seems like every time I do something in func, __index is invoked. It leads me to believe it might be the script debugger or something but I have no idea. Although I believe this only happens in studio as well, don't remember. If it's not the debugger then I have no idea what it is but they definitely tampered with Lua as it's invoked even when I define a local variable.

Ad

Answer this question