The ArkScript builtins
Those are C++ functions, using the ArkScript virtual machine API to communicate with it. They can be used as any other function in ArkScript code.
Basic template of a builtin
#include <Ark/VM/VM.hpp>
#include <Ark/VM/Value.hpp>
Ark::Value myBuiltin(std::vector<Ark::Value>& parameters, Ark::VM* vm)
{
return Ark::Nil;
}
See the tutorial on embedding for more details on how to use them.
Builtins category
We currently have a few categories for our builtins:
- IO, prefixed by `io:` in ArkScript
- List, prefixed by `list:` in ArkScript
- Mathematics, prefixed by `math:` in ArkScript
- String, prefixed by `string:` in ArkScript
- System, prefixed by `sys:` in ArkScript
- Time, prefixed by nothing in ArkScript
Adding a builtin
- You need to identify the category it belongs to
- Then add its prototype in `include/Ark/Builtins/Builtins.hpp` under the right namespace
- Add it to the builtins list in `src/arkreactor/Builtins/Builtins.cpp`, as follows: `{ "name", Value(category::functionName) }`
- The implementation will have to be done in `src/arkreactor/Builtins/{category}.cpp`
- Don't forget to document the new function, using the following snippet:
/**
* @name {function name}
* @brief {description}
* @details {optional, more details}
* @param {name1} {description}
* @param {name2} {description}
* =begin
* optional code sample to show how to use it
* =end
* @author {link to the author profile on github}
*/