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

Function main

examples/source/overloading.cpp:14–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12}
13
14int main() {
15 std::cout << "=== overloading ===" << std::endl;
16
17 sol::state lua;
18 lua.open_libraries(sol::lib::base);
19
20 // you can overload functions
21 // just pass in the different functions
22 // you want to pack into a single name:
23 // make SURE they take different types!
24
25 lua.set_function("func", sol::overload([](int x) { return x; }, make_string, my_add));
26
27 // All these functions are now overloaded through "func"
28 lua.script(R"(
29print(func(1))
30print(func("bark"))
31print(func(1,2))
32)");
33
34 std::cout << std::endl;
35
36 return 0;
37}

Callers

nothing calls this directly

Calls 3

overloadFunction · 0.85
open_librariesMethod · 0.80
scriptMethod · 0.80

Tested by

no test coverage detected