MCPcopy Create free account
hub / github.com/ThePhD/sol2 / main

Function main

examples/source/table_as_container.cpp:15–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13};
14
15int main() {
16 sol::state lua;
17 lua.open_libraries(sol::lib::base);
18
19 lua.new_usertype<Vector>("Vector",
20 sol::constructors<Vector(), Vector(int, int)>(),
21 "x",
22 sol::property(&Vector::x, &Vector::x),
23 "y",
24 sol::property(&Vector::y, &Vector::y));
25
26 lua.script(
27 "vectors = { Vector.new(3, 6), Vector.new(6, 3) }");
28 auto vectors = lua["vectors"].get<std::vector<Vector>>();
29
30 SOL_ASSERT(vectors[0].x == 3);
31 SOL_ASSERT(vectors[0].y == 6);
32
33 SOL_ASSERT(vectors[1].x == 6);
34 SOL_ASSERT(vectors[1].y == 3);
35
36 return 0;
37}

Callers

nothing calls this directly

Calls 3

propertyFunction · 0.85
open_librariesMethod · 0.80
scriptMethod · 0.80

Tested by

no test coverage detected