| 43 | } |
| 44 | |
| 45 | int 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) |
| 62 | local sli = SomeLib.getInstance() |
| 63 | |
| 64 | -- we use the `:` here because there is something to access |
| 65 | local value = sli:doSomething() |
| 66 | |
| 67 | -- check |
| 68 | print('sli:doSomething() returned:', value) |
| 69 | assert(value == 20) |
| 70 | )"); |
| 71 | |
| 72 | std::cout << std::endl; |
| 73 | return 0; |
| 74 | } |
nothing calls this directly
no test coverage detected