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

Function main

examples/source/require.cpp:25–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25int 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"(
41s = my_lib.some_class.new()
42assert(my_lib.func() == 2)
43s.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}

Callers

nothing calls this directly

Calls 3

open_librariesMethod · 0.80
requireMethod · 0.80
safe_scriptMethod · 0.80

Tested by

no test coverage detected