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

Function main

examples/source/runtime_additions.cpp:10–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8};
9
10int main(int, char*[]) {
11 std::cout << "=== runtime_additions ===" << std::endl;
12
13 sol::state lua;
14 lua.open_libraries(sol::lib::base);
15
16 lua.new_usertype<object>("object");
17
18 // runtime additions: through the sol API
19 lua["object"]["func"] = [](object& o) {
20 ++o.value;
21 return o.value;
22 };
23 // runtime additions: through a lua script
24 lua.script(R"(
25function object:print ()
26 print(self:func())
27end
28 )");
29
30 // see it work
31 lua.script(R"(
32obj = object.new()
33obj:print()
34 )");
35
36 object& obj = lua["obj"];
37 SOL_ASSERT(obj.value == 1);
38
39 return 0;
40}

Callers

nothing calls this directly

Calls 2

open_librariesMethod · 0.80
scriptMethod · 0.80

Tested by

no test coverage detected