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

Function main

examples/source/singleton.cpp:45–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45int main(int, char*[]) {
46 std::cout << "=== singleton ===" << std::endl;
47
48 sol::state lua;
49 lua.open_libraries(sol::lib::base);
50
51 lua.new_usertype<SomeLib>("SomeLib",
52 "new",
53 sol::no_constructor,
54 "getInstance",
55 &SomeLib::getInstance,
56 "doSomething",
57 &SomeLib::doSomething);
58
59 lua.script(R"(
60
61-- note we use the `.` here, not `:` (there's no self to access)
62local sli = SomeLib.getInstance()
63
64-- we use the `:` here because there is something to access
65local value = sli:doSomething()
66
67-- check
68print('sli:doSomething() returned:', value)
69assert(value == 20)
70)");
71
72 std::cout << std::endl;
73 return 0;
74}

Callers

nothing calls this directly

Calls 2

open_librariesMethod · 0.80
scriptMethod · 0.80

Tested by

no test coverage detected