| What do you want it to return though? x = f() or "default value" or maybe you want it to error x = f() or error"F failed" or maybe x is an object in which case you can just setmetatable(x,{__index = function () return "" --[[default value here]] end}) or maybe you don't want nils, in which case debug.setmetatable(nil, {}) -- actually this one is complicated, but yeah, you can use this. |
In cases where you really want to fetch the value or else get some default if it doesn't exist, there should be a way to do so that is distinct from regular dereferences and element access.