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

Function main

examples/source/usertype_initializers.cpp:51–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49};
50
51int main() {
52 std::cout << "=== usertype_initializers ===" << std::endl;
53 { // additional scope to make usertype destroy earlier
54 sol::state lua;
55 lua.open_libraries();
56
57 lua.new_usertype<holy>("holy",
58 "new",
59 sol::initializers(&holy::initialize),
60 "create",
61 sol::factories(&holy::create),
62 sol::meta_function::garbage_collect,
63 sol::destructor(&holy::destroy),
64 "data",
65 &holy::data);
66
67 lua.script(R"(
68h1 = holy.create()
69h2 = holy.new()
70print('h1.data is ' .. h1.data)
71print('h2.data is ' .. h2.data)
72)");
73 holy& h1 = lua["h1"];
74 holy& h2 = lua["h2"];
75 SOL_ASSERT(h1.data == 50);
76 SOL_ASSERT(h2.data == 0);
77 }
78 std::cout << std::endl;
79}

Callers

nothing calls this directly

Calls 5

initializersFunction · 0.85
factoriesFunction · 0.85
destructorFunction · 0.85
open_librariesMethod · 0.80
scriptMethod · 0.80

Tested by

no test coverage detected