SourceIndex
The SourceIndex contains methods for accessing modules and packages from source directories.
Summary
Methods
| GetModule (moduleName: string) : Variant |
| GetPackage (packageName: string) : Variant |
Methods
GetModule
Used to get a module from the given moduleName. Returns a ModuleSource if found, otherwise it will throw an error.
SourceIndex:GetModule ( moduleName: string ) : Variant
Parameters
| moduleName : string |
Returns
| Variant |
local Source = shared:GetService("Source")
local SharedSourceIndex: SourceIndex = Source:GetSharedSourceIndex()
local MyModule = SharedSourceIndex:GetModule("MyModule")
print(MyModule.foo())
--> "Hello World!"
GetPackage
Used to get a package from the given packageName. Returns a PackageSource if found, otherwise it will throw an error.
SourceIndex:GetPackage ( packageName: string ) : Variant
Parameters
| packageName : string |
Returns
| Variant |
local Source = shared:GetService("Source")
local SharedSourceIndex: SourceIndex = Source:GetSharedSourceIndex()
local MyPackage = SharedSourceIndex:GetPackage("MyPackage")
print(MyPackage.foo())
--> "Hello World!"
Package Context Warning
Only the server context and shared context have packages. Attempting to access GetPackage on a client GetContextSourceIndex SourceIndex will throw an error.
--// Client Context Script
local Source = shared:GetService("Source")
local ContextSourceIndex: SourceIndex = Source:GetContextSourceIndex()
local SharedSourceIndex: SourceIndex = Source:GetSharedSourceIndex()
--> this line will error
local SuperCoolPackage = ContextSourceIndex:GetPackage("SuperCoolPackage")
--> this line will not error
local SuperCoolPackage = SharedSourceIndex:GetPackage("SuperCoolPackage")