Ensure undefined global access is an error

1 vote · 0 comments

Requires that nothing special is already attached to the globals table.

Essentially, place this in your main loading path, and any time a global variable would return 'nil', an error is generated instead.

Note: The __index function, as intended, is never called for valid keys.

raw ·
· download
------------------------------------------------------------------------------- -- Ensure undefined global access is an error. ------------------------------------------------------------------------------- local global_meta = {} setmetatable(_G, global_meta) function global_meta:__index(k) error("Undefined global variable '" .. k .. "'!") end

Be the first to comment

Sign in with OpenID