Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline global exports for future-proofing and testing purposes #52

Open
rdw-software opened this issue May 29, 2022 · 1 comment
Open

Comments

@rdw-software
Copy link
Member

rdw-software commented May 29, 2022

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
end

This 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).

@rdw-software
Copy link
Member Author

Maybe this should be plugged into the runtime (evo-luvi) itself, as some globals are exported from there also?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant