Call a Function - C++ SDK
Atlas Device SDK は非推奨です。 詳細については、「非推奨 」のページを参照してください。
The examples on this page demonstrate calling an Atlas Function
named concatenate
that takes two arguments, concatenates them, and
returns the result:
// concatenate: concatenate two strings exports = function(a, b) { return a + b; };
Call a Function By Name
重要
Atlas Functions を使用する際は、コード インジェクションから保護するために、クライアント データを必ずサニタイズしてください。
To execute a function from the C++ SDK, use the
call_function()
member function on the user
object. Pass in the name of the
function as a string for the first parameter. This function takes two arguments,
which we provide as a string array of arguments:
// Connect to an App Services App and authenticate a user auto appConfig = realm::App::configuration(); appConfig.app_id = APP_ID; auto app = realm::App(appConfig); auto user = app.login(realm::App::credentials::anonymous()).get(); auto sync_config = user.flexible_sync_configuration(); // If the function takes arguments, pass them as a string array. // Any quotes within the array must be escaped. auto argArray = "[\"john.smith\", \"@companyemail.com\"]"; // Call an App Services function as the logged-in user auto result = user.call_function("concatenate", argArray).get(); // Verify that the result has a value CHECK(result); auto functionResult = result.value(); // Prints "Calling the concatenate function returned // "john.smith@companyemail.com"." std::cout << "Calling the concatenate function returned " << functionResult << ".\n";
The callback can provide an optional string result, or an optional error. In the example above, we check that the result has a value.