Help with getting environments if a function

Hello I don’t exactly understand getfenv too well, however if someone could solve it by answering a simple question.

Can I get the environment of where a function was called from inside that function, such that

local function foo()
  print(getenvironmentorsmth().variable) -- 'aaa'
end

local variable = 'aaa'
foo()

or does it only work vice versa where you can only get the environment of the function.

And in addition to this, would it work with metatables.

local t = setmetatable({}, {__index = function(self, index) 
  print(getenvironmentorsmth().variable) -- 'aaa'
end})

local variable = 'aaa'
workspace.Name = t[1]