Skip to content

Commit

Permalink
Lua: Add Vector:set(x, y, z)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 18, 2024
1 parent 18108c9 commit 9bc4513
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lua-api/lib/src/datatypes/Quaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace lua::datatypes {
void bind_quaternions(sol::state_view& lua) {
#define BIND_QUATERNION_LIKE(name, datatype) \
lua.new_usertype<name>(#name, \
"set", [](name& v, datatype x, datatype y, datatype z, datatype w) { v.x = x; v.y = y; v.z = z; v.w = w; }, \
"x", &name::x, \
"y", &name::y, \
"z", &name::z, \
Expand Down
12 changes: 11 additions & 1 deletion lua-api/lib/src/datatypes/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace lua::datatypes {
void bind_vectors(sol::state_view& lua) {
#define BIND_VECTOR3_LIKE(name, datatype) \
lua.new_usertype<name>(#name, \
"set", [](sol::object o, datatype x, datatype y, datatype z, datatype w) -> sol::object { \
name& v = o.as<name>(); \
v.x = x; v.y = y; v.z = z; \
return o; \
}, \
"clone", [](name& v) -> name { return v; }, \
"x", &name::x, \
"y", &name::y, \
Expand Down Expand Up @@ -38,7 +43,12 @@ namespace lua::datatypes {
BIND_VECTOR3_LIKE_END();

#define BIND_VECTOR4_LIKE(name, datatype) \
lua.new_usertype<name>(#name, \
lua.new_usertype<name>(#name, \
"set", [](sol::object o, datatype x, datatype y, datatype z, datatype w) -> sol::object { \
name& v = o.as<name>(); \
v.x = x; v.y = y; v.z = z; v.w = w; \
return o; \
}, \
"clone", [](name& v) -> name { return v; }, \
"x", &name::x, \
"y", &name::y, \
Expand Down

0 comments on commit 9bc4513

Please sign in to comment.