| 23 | } |
| 24 | |
| 25 | int main() { |
| 26 | std::cout << "=== require ===" << std::endl; |
| 27 | |
| 28 | sol::state lua; |
| 29 | lua.open_libraries(sol::lib::package, sol::lib::base); |
| 30 | // sol::c_call takes functions at the template level |
| 31 | // and turns it into a lua_CFunction |
| 32 | // alternatively, one can use |
| 33 | // sol::c_call<sol::wrap<callable_struct, |
| 34 | // callable_struct{}>> to make the call if it's a constexpr |
| 35 | // struct |
| 36 | lua.require("my_lib", |
| 37 | sol::c_call<decltype(&open_mylib), &open_mylib>); |
| 38 | |
| 39 | // run some code against your require'd library |
| 40 | lua.safe_script(R"( |
| 41 | s = my_lib.some_class.new() |
| 42 | assert(my_lib.func() == 2) |
| 43 | s.bark = 20 |
| 44 | )"); |
| 45 | |
| 46 | some_class& s = lua["s"]; |
| 47 | SOL_ASSERT(s.bark == 20); |
| 48 | std::cout << "s.bark = " << s.bark << std::endl; |
| 49 | |
| 50 | std::cout << std::endl; |
| 51 | |
| 52 | return 0; |
| 53 | } |
nothing calls this directly
no test coverage detected