1 #define SOL_ALL_SAFETIES_ON 1
2 #include <sol/sol.hpp>
3 
f1(int)4 int f1(int) {
5 	return 32;
6 }
7 
f2(int,int)8 int f2(int, int) {
9 	return 1;
10 }
11 
12 struct fer {
f3fer13 	double f3(int, int) {
14 		return 2.5;
15 	}
16 };
17 
main()18 int main() {
19 
20 	sol::state lua;
21 	// overloaded function f
22 	lua.set("f", sol::c_call<sol::wrap<decltype(&f1), &f1>, sol::wrap<decltype(&f2), &f2>, sol::wrap<decltype(&fer::f3), &fer::f3>>);
23 	// singly-wrapped function
24 	lua.set("g", sol::c_call<sol::wrap<decltype(&f1), &f1>>);
25 	// without the 'sol::wrap' boilerplate
26 	lua.set("h", sol::c_call<decltype(&f2), &f2>);
27 	// object used for the 'fer' member function call
28 	lua.set("obj", fer());
29 
30 	// call them like any other bound function
31 	lua.script("r1 = f(1)");
32 	lua.script("r2 = f(1, 2)");
33 	lua.script("r3 = f(obj, 1, 2)");
34 	lua.script("r4 = g(1)");
35 	lua.script("r5 = h(1, 2)");
36 
37 	// get the results and see
38 	// if it worked out
39 	int r1 = lua["r1"];
40 	sol_c_assert(r1 == 32);
41 	int r2 = lua["r2"];
42 	sol_c_assert(r2 == 1);
43 	double r3 = lua["r3"];
44 	sol_c_assert(r3 == 2.5);
45 	int r4 = lua["r4"];
46 	sol_c_assert(r4 == 32);
47 	int r5 = lua["r5"];
48 	sol_c_assert(r5 == 1);
49 
50 	return 0;
51 }
52