Created
March 14, 2016 22:11
-
-
Save ThePhD/470a3345d78f1ea4d291 to your computer and use it in GitHub Desktop.
We can do it!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SOL_CHECK_ARGUMENTS | |
#define SOL_NO_RTTI | |
#define SOL_NO_EXCEPTIONS // Just to prove that not having these on will still make it work | |
#include "sol.hpp" | |
struct A { | |
int a = 0xA; virtual int bark() { return 1; } | |
}; | |
std::tuple<int, int> bark(int num_value, A* a) { | |
return std::tuple<int, int>( num_value * 2, a->bark() ); | |
} | |
int main(int argc, char* const argv[]) { | |
sol::state lua; | |
lua.new_usertype<A>( "A", | |
"bark", &A::bark ); | |
lua.script(R"( function f (num_value, a) | |
return num_value * 2, a:bark() | |
end | |
nested = { variables = { no = { problem = 10 } } } )"); | |
lua.set_function("g", bark); | |
sol::function cpp_bark = lua["f"]; | |
sol::function lua_bark = lua["g"]; | |
sol::reference lua_variable_x = lua["nested"]["variables"]["no"]["problem"]; | |
A cpp_variable_y; | |
std::tuple<int, int> cppresult = cpp_bark(lua_variable_x, cpp_variable_y); | |
std::pair<int, int> luaresult = lua_bark(lua_variable_x, cpp_variable_y); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment