ImportPackage: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
(2 intermediate revisions by one other user not shown)
Line 3: Line 3:
{{FuncDescription|Creates a table holding all exported functions by another package.
{{FuncDescription|Creates a table holding all exported functions by another package.


''ImportPackage'' should only be called once in a package. The returned table is valid until package unload.}}
Another package should only be imported once by this function. The returned table is valid until package unload.}}


{{FuncSyntax|ImportPackage(PackageName)}}
{{FuncSyntax|ImportPackage(PackageName)}}
Line 26: Line 26:
print(test.UsefulFunc(2, 2))
print(test.UsefulFunc(2, 2))
</syntaxhighlight>
</syntaxhighlight>
''ImportPackage'' should only be called once in a package. The returned table is valid until package unload.
''ImportPackage'' can only be called once in a package serverside. The returned table is valid until package unload.
{{RelatedFunctions}}
{{RelatedFunctions}}
[[AddFunctionExport]]
[[AddFunctionExport]]

Revision as of 19:01, 19 September 2021

ImportPackage

Type: Function
Context: Server & Client
Introduced: v1.0

Description

Creates a table holding all exported functions by another package.

Another package should only be imported once by this function. The returned table is valid until package unload.

Syntax

ImportPackage(PackageName)

Parameters

  • PackageName
    Name of the package to import. Must be loaded before this one.

Return Value

  • Creates a table holding the other packages exported functions. Return nil if PackageName does not exist.

Example

Package Test1

function UsefulFunc(param1, param2)
    return param1 + param2
end
AddFunctionExport("UsefulFunc", UsefulFunc)

Package Test2

test = ImportPackage("Test1")

print(test.UsefulFunc(2, 2))

ImportPackage can only be called once in a package serverside. The returned table is valid until package unload.

See also

AddFunctionExport