Skip to content

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

@rdw-software

Description

@rdw-software

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions