2019-05-22 07:17:31 +08:00
|
|
|
#define SOL_ALL_SAFETIES_ON 1
|
2018-09-28 13:27:38 +08:00
|
|
|
#include <sol/sol.hpp>
|
2018-02-25 06:19:16 +08:00
|
|
|
|
|
|
|
|
2018-02-28 14:56:11 +08:00
|
|
|
int main(int, char*[]) {
|
2018-02-25 06:19:16 +08:00
|
|
|
|
|
|
|
struct test {
|
|
|
|
int blah = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
test t;
|
|
|
|
sol::state lua;
|
2021-03-06 14:03:23 +08:00
|
|
|
lua.set_function("f", [&t]() { return t; });
|
|
|
|
lua.set_function("g", [&t]() -> test& { return t; });
|
2018-02-25 06:19:16 +08:00
|
|
|
|
|
|
|
lua.script("t1 = f()");
|
|
|
|
lua.script("t2 = g()");
|
|
|
|
|
|
|
|
test& from_lua_t1 = lua["t1"];
|
|
|
|
test& from_lua_t2 = lua["t2"];
|
|
|
|
|
|
|
|
// not the same: 'f' lambda copied
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(&from_lua_t1 != &t);
|
2018-02-25 06:19:16 +08:00
|
|
|
// the same: 'g' lambda returned reference
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(&from_lua_t2 == &t);
|
2018-02-25 06:19:16 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|