Ensure undefined global access is an error

1 vote · 1 comment

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 ·
copy
· 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
Add a comment

1 Comment

How can I delete the duplicate?

Reply · May 28, 2014, 6:49 p.m.