Package
A Package is a normal Roblox ModuleScript that can return any datatype. SILK conveniently provides a number of pre-written packages known as essentials. Navigate to "Included Packages" to view a complete list.
External Dependencies
Including external dependencies inside the framework is as easy as just dropping it in. Simply drag and drop any ModuleScript dependencies inside a folder containing the rest of your packages and access it like you would for a regular package.
Implementation
Since a Package is just a ModuleScript, the implementation of one allows for flexibility for developers to adapt the package to their needs. However, the most common implementation of a Package is shown below.
Typical implementation of a Package:
--|| Package.lua ||
local package = {}
package.__index = package
-- Optionally indicate that the package is a singleton
package.__singleton = true
-- This is called whenever this package is referenced or once if the package is a singleton
-- Conveniently access the Silk object
package.__initialize = function(silk)
-- Store silk within the package for future use
package.silk = silk
-- This is the value that is returned during runtime
-- If the package is a singleton, this return value is cached internally
return package
end
function package.new()
return setmetatable({}, package)
end
-- If a package contains package.__initialize, the method is called and the value that it returns is cached instead during runtime
return package
Management
All packages should be added in using the Silk.AppendPackages method during the initializer phase.
Storing Packages
When storing package, place them in a secure location alongside all your other packages. For example, a folder containing all your shared packages.
Adding in packages through the initializer script:
--|| initializer.server.lua ||
silk:AppendPackages{
-- Directory that contains all the packages
silk.ReplicatedStorage:WaitForChild('Packages'),
}
Usage
Initialize and return contents of package:
-- Access packages immediately after they're added
local package = silk.Packages.Package
Alternatively, when intialization for singleton packages is required during the initializer phase, instead of initializing the package directly using silk.Packages.<Package>
, use Silk.InitPackage.
Intializing a package directly:
-- Initialize the package directly
silk:InitPackage('Package')
Properties
__domain
Package.__domain:
string
An optional meta attribute used to place domain restriction on a package. The default behaviour is shared
. Change the attribute to server
or local
to restrict access.
__singleton
Package.__singleton:
boolean
An optional meta attribute that can be included in any package. If set to true, a cached reference to the package is returned whenever the package is referenced.
info
If Package.__initialize is also provided, the return value recieved after calling this method is cached instead.
Functions
__initialize
An optional meta function that can be included in any package. This method should typically be used when further initialization (using Silk) is required before returning the package.