You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Craig Minihan edited this page Dec 7, 2016
·
6 revisions
This example defines a global function called echo which prints the first parameter as a string on stdout. The function is invoked via JSAPI and then from JavaScript.
#include<iostream>
#include"libjsapi.h"intmain() {
rs::jsapi::Context cx;
// define a global function called echo which// prints the first argument on stdoutrs::jsapi::Global::DefineFunction(cx, "echo",
[](const std::vector<rs::jsapi::Value>& args, rs::jsapi::Value& result) {
if (args.size() > 0) {
std::cout << args[0] << std::endl;
}
});
// invoke echo passing a string
rs::jsapi::FunctionArguments args(cx);
args.Append("Hello world!!");
cx.Call("echo", args);
// call the function from JavaScript
cx.Evaluate("echo('lorem ipsum...');");
}