-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_method_field_access.cpp
More file actions
41 lines (34 loc) · 1.17 KB
/
test_method_field_access.cpp
File metadata and controls
41 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <jaiscript/core/engine.hpp>
#include <jaiscript/stdlib/stdlib.hpp>
#include <iostream>
int main() {
auto engine = jai::engine::make();
jai::stdlib::register_all(*engine);
try {
engine->execute(R"(
class Node {
string name = "";
array<Node> children = [];
Node(string n) {
name = n;
}
auto add_child(Node child) {
print("In add_child, about to push");
children.push(child);
print("After push, children size = " + to_string(children.size()));
}
}
auto root = shared_ptr<Node>(Node("root"));
auto child1 = shared_ptr<Node>(Node("child1"));
print("Before add_child");
root.add_child(child1);
print("After add_child");
print("Root children size = " + to_string(root.children.size()));
)");
std::cout << "Test completed" << std::endl;
return 0;
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
return 1;
}
}