| 8 | }; |
| 9 | |
| 10 | int 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"( |
| 25 | function object:print () |
| 26 | print(self:func()) |
| 27 | end |
| 28 | )"); |
| 29 | |
| 30 | // see it work |
| 31 | lua.script(R"( |
| 32 | obj = object.new() |
| 33 | obj:print() |
| 34 | )"); |
| 35 | |
| 36 | object& obj = lua["obj"]; |
| 37 | SOL_ASSERT(obj.value == 1); |
| 38 | |
| 39 | return 0; |
| 40 | } |
nothing calls this directly
no test coverage detected