// 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);
}
DLL 定義所有需要的 JS API 後,外掛程式必須告訴 FormIt 需要載入的 DLL。這可在 manifest 中完成。