AddFunctionExport: Difference between revisions

From Onset Developer Wiki
(Created page with "{{Info|Function|Server & Client|1.0}} {{FuncDescription|Exports a function that can later be imported from another package.}} {{FuncSyntax|AddFunctionExport(ExportName, Expo...")
 
No edit summary
 
Line 25: Line 25:
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.
{{RelatedFunctions}}
{{RelatedFunctions}}
[[ImportPackage]]
[[ImportPackage]]

Latest revision as of 19:25, 29 March 2021

AddFunctionExport

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

Description

Exports a function that can later be imported from another package.

Syntax

AddFunctionExport(ExportName, ExportFunction)

Parameters

  • ExportName
    Name of the export. Commonly the name of the exported function.
  • ExportFunction
    Function to export.

Return Value

  • Returns true on success. Return false if the export already exists.

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 should only be called once in a package. The returned table is valid until package unload.

See also

ImportPackage