Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Created December 9, 2013 19:17
Show Gist options
  • Save ThePhD/7879075 to your computer and use it in GitHub Desktop.
Save ThePhD/7879075 to your computer and use it in GitHub Desktop.
Sol Tuple and function tests
void breaking() {
std::cout << "Nice!~\n";
}
std::tuple<double, double> breaking_multi() {
return std::make_tuple(567.2, 2.567);
}
struct a_type {
std::tuple<double, double> breaking_multi() {
return std::make_tuple(567.2, 2.567);
}
};
int main() {
sol::state lua;
a_type at;
int a = 10;
int b = 11;
auto breaking_lambda = [ ] () { std::cout << "Nice Lambda!\n"; };
lua.set_function("arf", breaking);
lua.set_function("arflambda", breaking_lambda);
lua.set_function("arfmulti", breaking_multi);
lua.set_function("arfmulti", &a_type::breaking_multi, at);
lua.script("arf()\n"
"arflambda()\n"
"x,y = arfmulti()\n"
"function add_double(a, b)\n"
" return a + b, a + b;\n"
"end\n"
"function add(a, b)\n"
" return a + b;\n"
"end\n"
"function ultra_add(a, b, c)\n"
" return a + b + c;\n"
"end");
auto fd = lua.get<sol::function>("add_double");
auto f = lua.get<sol::function>("add");
auto fx = lua.get<sol::function>("ultra_add");
std::tuple<int, int> arf = fd.invoke<int, int>(10, 10); // 20, 20
std::cout << lua.get<double>("x") << ", " << lua.get<double>("y") << std::endl;
std::cout << std::get<0>(arf) << ", " << std::get<1>(arf) << std::endl; // 21
std::cout << f.invoke<int>(a, b) << std::endl; // 21
std::cout << fx.invoke<int>(a, a, b) << std::endl; // 31
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment