From dc2493e7525bb7633f697ef10f72b72b46222249 Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Fri, 30 Aug 2019 00:45:36 -0400 Subject: Forget what I said, I just need to change git attributes to mark for vendor --- lib/sol2/examples/source/c_call.cpp | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/sol2/examples/source/c_call.cpp (limited to 'lib/sol2/examples/source/c_call.cpp') diff --git a/lib/sol2/examples/source/c_call.cpp b/lib/sol2/examples/source/c_call.cpp new file mode 100644 index 0000000..4758705 --- /dev/null +++ b/lib/sol2/examples/source/c_call.cpp @@ -0,0 +1,50 @@ +#define SOL_ALL_SAFETIES_ON 1 +#include + +#include "assert.hpp" + +int f1(int) { return 32; } + +int f2(int, int) { return 1; } + +struct fer { + double f3(int, int) { + return 2.5; + } +}; + + +int main() { + + sol::state lua; + // overloaded function f + lua.set("f", sol::c_call, sol::wrap, sol::wrap>); + // singly-wrapped function + lua.set("g", sol::c_call>); + // without the 'sol::wrap' boilerplate + lua.set("h", sol::c_call); + // object used for the 'fer' member function call + lua.set("obj", fer()); + + // call them like any other bound function + lua.script("r1 = f(1)"); + lua.script("r2 = f(1, 2)"); + lua.script("r3 = f(obj, 1, 2)"); + lua.script("r4 = g(1)"); + lua.script("r5 = h(1, 2)"); + + // get the results and see + // if it worked out + int r1 = lua["r1"]; + c_assert(r1 == 32); + int r2 = lua["r2"]; + c_assert(r2 == 1); + double r3 = lua["r3"]; + c_assert(r3 == 2.5); + int r4 = lua["r4"]; + c_assert(r4 == 32); + int r5 = lua["r5"]; + c_assert(r5 == 1); + + return 0; +} -- cgit v1.2.3