Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/embind/test_embind_val_basics.cpp
4150 views
1
#include <stdio.h>
2
#include <emscripten/val.h>
3
4
using namespace emscripten;
5
6
int main() {
7
val Math = val::global("Math");
8
9
// two ways to call Math.abs
10
printf("abs(-10): %d\n", Math.call<int>("abs", -10));
11
printf("abs(-11): %d\n", Math["abs"](-11).as<int>());
12
13
// Const-qualification and references should not matter.
14
int x = -12;
15
const int y = -13;
16
printf("abs(%d): %d\n", x, Math.call<int>("abs", x)); // x is deduced to int&
17
printf("abs(%d): %d\n", y, Math.call<int>("abs", y)); // y is deduced to const int&
18
printf("abs(-14): %d\n", Math.call<const int>("abs", -14));
19
20
return 0;
21
}
22
23