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-03-16 05:16:28 +08:00
|
|
|
|
|
|
|
|
2021-03-06 14:03:23 +08:00
|
|
|
int main(int, char*[]) {
|
2018-03-16 05:16:28 +08:00
|
|
|
|
|
|
|
const auto& code = R"(
|
|
|
|
bark_power = 11;
|
|
|
|
|
|
|
|
function woof ( bark_energy )
|
|
|
|
return (bark_energy * (bark_power / 4))
|
|
|
|
end
|
|
|
|
)";
|
|
|
|
|
|
|
|
sol::state lua;
|
|
|
|
|
|
|
|
lua.script(code);
|
|
|
|
|
|
|
|
sol::function woof = lua["woof"];
|
|
|
|
double numwoof = woof(20);
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(numwoof == 55.0);
|
2018-03-16 05:16:28 +08:00
|
|
|
|
2021-03-06 14:03:23 +08:00
|
|
|
lua.script("function f () return 10, 11, 12 end");
|
2018-03-16 05:16:28 +08:00
|
|
|
|
|
|
|
sol::function f = lua["f"];
|
|
|
|
std::tuple<int, int, int> abc = f();
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(std::get<0>(abc) == 10);
|
|
|
|
SOL_ASSERT(std::get<1>(abc) == 11);
|
|
|
|
SOL_ASSERT(std::get<2>(abc) == 12);
|
2018-03-16 05:16:28 +08:00
|
|
|
// or
|
|
|
|
int a, b, c;
|
|
|
|
sol::tie(a, b, c) = f();
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(a == 10);
|
|
|
|
SOL_ASSERT(b == 11);
|
|
|
|
SOL_ASSERT(c == 12);
|
2018-03-16 05:16:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|