{"id":"sap0bombado/quill-core","name":"quill-core","scope":"sap0bombado","platform":"roblox","description":"A featherweight framework for Luau","version":"0.1.0-alpha.2","latest":"0.1.0-alpha.2","versions":["0.1.0-alpha.2"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"cb98fba7842e4164ec092ca409a6089a8acfd57658d3a7065d6ad6be867b735d","likes":0,"downloads":0,"install":"forest install sap0bombado/quill-core","url":"https://forest.dev/p/roblox/sap0bombado/quill-core","files":"https://api.forest.dev/ai/package/roblox/sap0bombado/quill-core/files","readme":"# Core\r\n\r\nThe core crate of Quill.\r\n\r\n## Defining singletons\r\n\r\nA singleton is defined to be a table of any shape and type, with optionally an init and start method.\r\n```luau\r\nexport type Singleton = {\r\n    init: ((Singleton) -> ())?,\r\n    start: ((Singleton) -> ())?,\r\n    [any]: any,\r\n}\r\n```\r\n\r\nInit is executed after all modules are loaded and **cannot yield**.<br>\r\nStart is executed after all modules are initialized and can yield, as it's ran in another thread with `task.spawn`.\r\n\r\n```luau\r\nlocal MySingleton = {}\r\n\r\nfunction MySingleton.init(self: self)\r\n    -- Initialize your properties and everything that other singletons may depend on here.\r\n    -- For example, you'd initialize your datastore wrapper or signals in this function.\r\nend\r\n\r\nfunction MySingleton.start(self: self)\r\n    -- Run your singletons' logic here.\r\n    -- For example, you'd put a game loop here.\r\nend\r\n\r\n-- Allows for easy typechecking of any properties and methods.\r\nexport type self = typeof(MySingleton)\r\nreturn MySingleton\r\n```\r\n\r\n## Defining modules\r\n\r\nModules are Quill extensions which can hook onto:\r\n- Singleton lifecycles:\r\n  - `injected` - called once a singleton has been injected by the user with `Quill:with_singleton` or `Quill:with_singletons`\r\n  - `loaded` - called once a singleton's modulescript has been loaded by the module loader; injected modules are skipped by this, as the user passes a loaded singleton to the framework in place of a module\r\n  - `initialized` - called once a singleton has been initialized; immediately if it doesn't have an `:init ` method, or if it has one, after it was called\r\n  - `started` - called once a singleton has been started; immediately if it doesn't have a `:start` method, or if it has one, after it was called\r\n- Module loader phases:\r\n  - `pre_loading` - called before any modules are loaded; injected modules are loaded prior to this, as the user passes a loaded singleton to the framework in place of a module \r\n  - `post_loading` - called after all modules were loaded\r\n  - `pre_initialization` - called before singletons are initialized\r\n  - `post_initialization` - called after singletons are initialized\r\n  - `pre_starting` - called before singletons are started\r\n  - `post_starting` - called after singletons are started\r\n\r\nLifecycle hooks are called with a singleton and its current lifecycle:\r\n```luau\r\ntype LifecycleHook = (lifecycle: Lifecycle, singleton: Singleton) -> ()\r\n```\r\n\r\nPhases are called with a list of all singletons currently attached to the framework and the current module loader phase:\r\n```luau\r\ntype PhaseHook = (phase: Phase, singletons: { Singleton }) -> ()\r\n```\r\n\r\n## Building and starting the framework\r\n\r\nAfter creating quill with `Quill.new`, you may:\r\n- Add Quill modules with `Quill:with_mod`\r\n- Add modulescripts with `Quill:with_module` and `Quill:with_modules`\r\n- Inject singletons with `Quill:with_singleton` and `Quill:with_singletons`\r\n- Lastly, start Quill with `Quill:write`\r\n\r\nIdeally, you'd add Quill modules prior to anything else, as injecting singletons runs the injected lifecycle hooks for them.\r\n\r\nFor example:\r\n```luau\r\nlocal quill = require(\"@pkg/quill\")\r\nlocal rblx_lifecycles = require(\"@pkg/quill_rblx_lifecycles\")\r\n\r\nquill.new()\r\n    :with_mod(rblx_lifecycles.mod)\r\n    :with_modules(script.singletons:GetChildren())\r\n    :write()\r\n```\r\n","readmeTruncated":false}