forked from ThePhD/sol2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua_zm_interop.cpp
More file actions
38 lines (33 loc) · 1.09 KB
/
lua_zm_interop.cpp
File metadata and controls
38 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <lua_zm_interop.hpp>
#include <zm/vec3.hpp>
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
bool sol_lua_check(sol::types<zm::vec3>, lua_State* L, int index,
std::function<sol::check_handler_type> handler,
sol::stack::record& tracking) {
// use sol's method for checking
// specifically for a table
return sol::stack::check<sol::lua_table>(
L, index, handler, tracking);
}
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);
float x = vec3table["x"];
float y = vec3table["y"];
float z = vec3table["z"];
return zm::vec3 { x, y, z };
}
int sol_lua_push(
sol::types<zm::vec3>, lua_State* L, const zm::vec3& v) {
// create table
sol::state_view lua(L);
sol::table vec3table = sol::table::create_with(
L, "x", v.x, "y", v.y, "z", v.z);
// use base sol method to
// push the table
int amount = sol::stack::push(L, vec3table);
// return # of things pushed onto stack
return amount;
}