// FormIt looks for REGISTERAPIMETHODS to load new JS APIs
REGISTERAPIMETHODS
{
// Declare new namespace for the new JS APIs
REGISTERNAMESPACE("HelloDLL")
// Create a JS API with no arguments
APIMETHOD(HelloDLL, API1, "") {}
// Create a JS API with 1 argument
APIMETHOD(HelloDLL, API2, "arg1") {}
// Create a JS API with 2 argument
APIMETHOD(HelloDLL, API3, "arg1, arg2") {}
...
...
}
要将参数转换为 C++ 变量,请使用 SCRIPTCONVERTER-
// Create a JS API with 2 argument
APIMETHOD(HelloDLL, API3, "arg1, arg2")
{
// NOTE: The arg names above ^^^^ have to match the args in the macros below.
// arg1 expects a bool
SCRIPTCONVERTER(bool, arg1);
// arg2 expects an int
SCRIPTCONVERTER(int, arg2);
return JSON_UNDEFINED;
}
可以返回 JSON_UNDEFINED 或任何 json 对象。使用 to_json 将 C++ 变量转换为 json
// Create a JS API with 2 argument
APIMETHOD(HelloDLL, API3, "arg1, arg2")
{
// NOTE: The arg names above ^^^^ have to match the args in the macros below.
// arg1 expects a bool
SCRIPTCONVERTER(bool, arg1);
// arg2 expects an int
SCRIPTCONVERTER(int, arg2);
std::string myValue = "Test";
return to_json(myValue);
}