2019-09-01 14:27:58 +08:00
|
|
|
#include <lua_zm_interop.hpp>
|
|
|
|
|
|
|
|
#include <zm/vec3.hpp>
|
|
|
|
|
|
|
|
#define SOL_ALL_SAFETIES_ON 1
|
|
|
|
#include <sol/sol.hpp>
|
|
|
|
|
2021-03-06 23:14:48 +08:00
|
|
|
bool sol_lua_check(sol::types<zm::vec3>, lua_State* L, int index,
|
|
|
|
std::function<sol::check_handler_type> handler,
|
|
|
|
sol::stack::record& tracking) {
|
2019-09-01 14:27:58 +08:00
|
|
|
// use sol's method for checking
|
|
|
|
// specifically for a table
|
2021-03-06 23:14:48 +08:00
|
|
|
return sol::stack::check<sol::lua_table>(
|
|
|
|
L, index, handler, tracking);
|
2019-09-01 14:27:58 +08:00
|
|
|
}
|
|
|
|
|
2021-03-06 23:14:48 +08:00
|
|
|
zm::vec3 sol_lua_get(sol::types<zm::vec3>, lua_State* L,
|
|
|
|
int index, sol::stack::record& tracking) {
|
|
|
|
sol::lua_table vec3table
|
|
|
|
= sol::stack::get<sol::lua_table>(L, index, tracking);
|
2019-09-01 14:27:58 +08:00
|
|
|
float x = vec3table["x"];
|
|
|
|
float y = vec3table["y"];
|
|
|
|
float z = vec3table["z"];
|
2021-03-06 14:03:23 +08:00
|
|
|
return zm::vec3 { x, y, z };
|
2019-09-01 14:27:58 +08:00
|
|
|
}
|
|
|
|
|
2021-03-06 23:14:48 +08:00
|
|
|
int sol_lua_push(
|
|
|
|
sol::types<zm::vec3>, lua_State* L, const zm::vec3& v) {
|
2019-09-01 14:27:58 +08:00
|
|
|
// create table
|
|
|
|
sol::state_view lua(L);
|
2021-03-06 23:14:48 +08:00
|
|
|
sol::table vec3table = sol::table::create_with(
|
|
|
|
L, "x", v.x, "y", v.y, "z", v.z);
|
2019-09-01 14:27:58 +08:00
|
|
|
// use base sol method to
|
|
|
|
// push the table
|
|
|
|
int amount = sol::stack::push(L, vec3table);
|
|
|
|
// return # of things pushed onto stack
|
|
|
|
return amount;
|
|
|
|
}
|