exportFunction: Difference between revisions

From GTA Connected
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
Line 9: Line 9:
|returnFail1 = void
|returnFail1 = void
|returnInfo = a boolean, indicating whether the function has been exported or not
|returnInfo = a boolean, indicating whether the function has been exported or not
|notes = To use this function in another resource, use [[findResourceByName|findResourceByName]] in the other resource, which returns a resource object. You can then use [[resource.exports|resource.exports]] or [[resource.getExport|resource.getExport]] to access exported functions.
|note1 = To use this function in another resource, use [[findResourceByName|findResourceByName]] in the other resource, which returns a resource object. You can then use [[resource.exports|resource.exports]] or [[resource.getExport|resource.getExport]] to access exported functions.
|note2 = Only simple types (string, number, boolean, null) are guaranteed to work across resource boundaries. Passing compound types (objects, arrays, tables) is discouraged — depending on the language combination involved, this may cause crashes or undefined behaviour. If structured data must be passed, serialize it to a JSON string before the call and deserialize on the receiving side.
|usage = export a function so it can be used in other resources
|usage = export a function so it can be used in other resources
|exampleJS = bindEventHandler("OnResourceStart", thisResource, function(event, resource) {
|exampleJS = bindEventHandler("OnResourceStart", thisResource, function(event, resource) {
     exportFunction("testFunc", testFunc);
     exportFunction("testFunc", testFunc);
});
});
function testFunc(foo, bar) {
function testFunc(foo, bar) {
     return true;
     return true;
}
}
}}
}}

Latest revision as of 02:31, 10 April 2026

Function Server and Client GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png Online and Offline

Available since Server 1.0.0, Client 1.0.0
void exportFunction(string name, function Function)
The exportFunction function is used to export a function so it can be used in other resources.

Parameters

1) string name The name of the exported function.
2) function Function The function to export.

Return

void This function doesn't return a value.

Notes

  • To use this function in another resource, use findResourceByName in the other resource, which returns a resource object. You can then use resource.exports or resource.getExport to access exported functions.
  • Only simple types (string, number, boolean, null) are guaranteed to work across resource boundaries. Passing compound types (objects, arrays, tables) is discouraged — depending on the language combination involved, this may cause crashes or undefined behaviour. If structured data must be passed, serialize it to a JSON string before the call and deserialize on the receiving side.

Examples

Example 1 - JavaScript:

bindEventHandler("OnResourceStart", thisResource, function(event, resource) {
    exportFunction("testFunc", testFunc);
});
function testFunc(foo, bar) {
    return true;
}

Compatibility

There isn't any compatibility information for this function.

Related

Server Related

GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png exportFunction

GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.call
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.clone
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.createFunction
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.move
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.tostring


Client Related

GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png exportFunction

GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.call
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.clone
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.createFunction
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.move
GTAIII Logo.png icon-vc.png icon-sa.png icon-iv.png reflection.tostring