-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Currently, builtins and APIs are simply exported via _G.SomeObject = SomeObject. While that works, it will be very difficult to ever change the behavior across the entire codebase. It's also annoying to test, since messing with the global environment without following a predefined protocol could have plenty of unintended side effects.
To that end, all global exports that exist on purpose, i.e., are not "leaked globals", should follow the following convention:
EXPORT("SomeObject", SomeObject)where
function _G.export(name, objectToExport)
-- Sanity checks, etc and print warning if it already exists?
-- log TRACE("Exported global SomeObject" ?
-- etc.
_G[name] = objectToExport
endThis consolidates all modifications of the global environment and provides a streamlined way of doing so that allows mocking (for tests), documenting automatically (scan for export calls), and refactoring/changes in the design (search for export calls in the code).