callExtension: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) (wip) |
Killzone Kid (talk | contribs) No edit summary |
||
Line 43: | Line 43: | ||
|x1= <code>_return = "myExtension" [[callExtension]] "stringToBeParsed";</code>|= EXAMPLE1 | |x1= <code>_return = "myExtension" [[callExtension]] "stringToBeParsed";</code>|= EXAMPLE1 | ||
|x2= <code>_result = "test_extension" [[callExtension]] [[str]] [[ | |x2= <code>_result = "test_extension" [[callExtension]] [[str]] [[weapons]] [[player]]; | ||
_result = "test_extension" [[callExtension]] ["fnc1", [[getUnitLoadout]] [[player]]]; | _result = "test_extension" [[callExtension]] ["fnc1", [[getUnitLoadout]] [[player]]]; | ||
_result = "test_extension" [[callExtension]] ["fnc1", [[ | _result = "test_extension" [[callExtension]] ["fnc2", [[magazinesAmmoFull]] [[player]]]; | ||
_result = "test_extension" [[callExtension]] ["fnc1", <nowiki>[</nowiki>[[weapons]] [[player]],[[magazines]] [[player]]]];</code> | |||
<u>Source Code</u><br><br> | <u>Source Code</u><br><br> | ||
This is an example of an extension compatible with both syntaxes. When using 1st syntax, the data is just copied from input to output. When using alt syntax, the arguments are parsed and then assembled back into string array in 2 ways: fnc1 and fnc2. fnc1 is a fraction faster. | This is an example of an extension compatible with both syntaxes. When using 1st syntax, the data is just copied from input to output. When using alt syntax, the arguments are parsed and then assembled back into string array in 2 ways: fnc1 and fnc2. fnc1 is a fraction faster. |
Revision as of 10:58, 26 January 2017
Description
- Description:
- Calls custom .dll also known as Extension.
Since Arma 3 v1.67 it is possible to pass array of arguments to extension.
Possible error codes:- 101: SYNTAX_ERROR_WRONG_PARAMS_SIZE
- 102: SYNTAX_ERROR_WRONG_PARAMS_TYPE
- 201: PARAMS_ERROR_TOO_MANY_ARGS
- 301: EXECUTION_WARNING_TAKES_TOO_LONG
- Groups:
- Uncategorised
Syntax
- Syntax:
- extension callExtension function
- Parameters:
- extension: String - extension name
- function: String - data send to the extension
- Return Value:
- String - data sent back from extension
Alternative Syntax
- Syntax:
- extension callExtension [function, arguments] (Since Arma 3 v1.67)
- Parameters:
- extension: String - extension name
- [function, arguments]: Array - callExtension params
- function: String - extension function identifier
- arguments: Array - function arguments. Could be array of Anything, each element will be converted to String automatically. Current allowed max length of this array is 1024
- Return Value:
- Array - in format [result, returnCode, errorCode], where:
Examples
- Example 1:
_return = "myExtension" callExtension "stringToBeParsed";
- Example 2:
_result = "test_extension" callExtension str weapons player; _result = "test_extension" callExtension ["fnc1", getUnitLoadout player]; _result = "test_extension" callExtension ["fnc2", magazinesAmmoFull player]; _result = "test_extension" callExtension ["fnc1", [weapons player,magazines player]];
Source Code
This is an example of an extension compatible with both syntaxes. When using 1st syntax, the data is just copied from input to output. When using alt syntax, the arguments are parsed and then assembled back into string array in 2 ways: fnc1 and fnc2. fnc1 is a fraction faster.#include <string> #include <vector> #include <iterator> #include <sstream> extern "C" { //--- STRING callExtension STRING __declspec (dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function); //--- STRING callExtension ARRAY __declspec (dllexport) int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **args, int argsCnt); } //--- name callExtension function void __stdcall RVExtension(char *output, int outputSize, const char *function) { std::string str = function; strncpy_s(output, outputSize, ("Input Was: " + str).c_str(), _TRUNCATE); } //--- name callExtension [function, args] int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **args, int argsCnt) { if (strcmp(function, "fnc1") == 0) { //--- Manually assemble output array int i = 0; std::string str = "["; //--- Each argument can be accessed via args[n] if (argsCnt > 0) str += args[i++]; while (i < argsCnt) { str += ","; str += args[i++]; } str += "]"; //--- Extension result strncpy_s(output, outputSize, str.c_str(), _TRUNCATE); //--- Extension return code return 100; } else if (strcmp(function, "fnc2") == 0) { //--- Parse args into vector std::vector<std::string> vec(args, std::next(args, argsCnt)); std::ostringstream oss; if (!vec.empty()) { //--- Assemble output array std::copy(vec.begin(), vec.end() - 1, std::ostream_iterator<std::string>(oss, ",")); oss << vec.back(); } //--- Extension result strncpy_s(output, outputSize, ("[" + oss.str() + "]").c_str(), _TRUNCATE); //--- Extension return code return 200; } else { strncpy_s(output, outputSize, "Avaliable Functions: fnc1, fnc2", outputSize - 1); return -1; } }
Additional Information
- See also:
- callcompileparseSimpleArrayExtensions
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Notes
Bottom Section
Categories:
- Scripting Commands
- Introduced with Arma 2: Operation Arrowhead version 1.60
- Arma 2: Operation Arrowhead: New Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Command Group: Uncategorised
- Scripting Commands ArmA2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters
- ArmA 2 OA: New Scripting Commands List