I'm trying to get the stack level of a certain scope, and kinda confused on how i can successfully do this. Here's what I've tried so far:
local function GetStackLevel(Env)
local stack=1
local current=getfenv(0)
setfenv(1,Env)
while getfenv(stack)~=current do
stack=stack+1
end
print(stack)
end
setfenv(1,{x=1,print=print,getfenv=getfenv})
GetStackLevel(getfenv())
print(getfenv(2))
However, the GetStackLevel function returns "3", while the maximum level I can get with getfenv in that environment is 2. Can anyone help?
