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

Function main

examples/source/docs/as_function.cpp:4–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <sol/sol.hpp>
3
4int main() {
5 struct callable {
6 int operator()(int a, bool b) {
7 return a + (b ? 10 : 20);
8 }
9 };
10
11
12 sol::state lua;
13 // Binds struct as userdata
14 // can still be callable, but beware
15 // caveats
16 lua.set("not_func", callable());
17 // Binds struct as function
18 lua.set("func", sol::as_function(callable()));
19 // equivalent: lua.set_function( "func", callable() );
20 // equivalent: lua["func"] = callable();
21}

Callers

nothing calls this directly

Calls 3

as_functionFunction · 0.85
callableClass · 0.70
setMethod · 0.45

Tested by

no test coverage detected