How to know how many stack levels are available in current getfenv?

As described in Lua Globals | Roblox Creator Documentation, I can get the environment variables of a given level by providing the number of that level as an argument to getfenv.
Ex: print(getfenv(2)) will list all environment variables inside stack 2.
The problem is that there are not always levels > 1.
So I would like to know if there is a way to know how many stack levels are available for getfenv?