So, i know that getfenv() returns the global function environment. However, I've been messing around with it a bit, and it just seems to me that the argument in getfenv() is useless? Here are some examples I've tried:
a = 1
b = 2
local function v()
c = 3
end
for i,v in pairs (getfenv(v)) do
print(i,v)
end
-- Output -- >> a 1, b 2, c 3, script Script
-- But why? I thought i was getting the function environment for "v" only?
Here's another:
a = 1
local function x()
b = 2
local function v()
for i,v in pairs (getfenv(2)) do -- Now using 2 to represent the stack level (which should be in function "x"?)
print(i,v)
end
end
v()
end
x()
-- Output -- >a 1, b 2, script Script
Real question
So i guess my question is, why does getfenv(function/stack level) constantly return the global script environment when i specifically gave it a function environment to return (oppose to the global one)? Thank you for your time, and hope you can help.

2 comments
https://scriptinghelpers.org/questions/21259/what-does-the-1-mean-in-getfenv1
From that Q: "Normally, the 'environment' of every function is just the table of global variables. This will only be changed with setfenv."