Repository navigation
Library: Namespace
ᴏᴠ ━ ᴀɴɪꜱᴀ edited this page Dec 5, 2024
·
12 revisions
This module provides a robust implementation of namespaces and classes in Lua, offering:
- Controlled variable and handler scope management.
- Code organization into logical groups.
- Prevention of naming collisions.
- Support for public and private members.
- Lightweight class simulation with instance management.
- Namespace and class creation with scope control.
- Public and private member support.
- Nested class and namespace capabilities.
- Safe instance management.
Add the below code once in either of the shared .lua script of the resource you want to use within:
--Declare it globally only once
loadstring(exports.assetify_library:import("namespacer"))()--Note: Public & Private members can be appended later via cNamespace.public & cNamespace.private respectively.
local namespace: cNamespace = assetify.namespace:create(
string: name, --Name of your namespace
table: parent --(Optional) Any non class table that you wish to utilize for creating the namespace
)local bool: result = assetify.namespace:destroy(
string: name --Name of your namespace
)local string: name = self:getName()--Note: Public & Private members can be appended later via cClass.public & cClass.private respectively.
local class: cClass = assetify.class:create(
string: name, --Name of your class
table: parent, --(Optional) Any non class table that you wish to utilize for creating the class
string: namespace --(Optional) Valid namespace that you prefer to scope the class within. If not specified the instance will be created within the global scope
)local bool: result = assetify.class:destroy(
class: instance
)local bool: result = self:isInstance(
class <instance>: cInstance
)local class <instance>: cInstance = self:createInstance()local bool: result = cInstance:destroyInstance()