Skip to content

Commit

Permalink
Merge branch 'luaapi-vec_ex' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
odorajbotoj committed Oct 15, 2024
2 parents 90afa56 + 0af0136 commit 85b3c43
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 30 deletions.
38 changes: 25 additions & 13 deletions src/cfsp/simplayer/luaapi/Vec2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "mc/math/Vec2.h"
#include "cfsp/base/Macros.h"
#include "cfsp/simplayer/luaapi/Utils.h"
#include "mc/math/Vec3.h"
#include <string>

extern "C" {
Expand Down Expand Up @@ -98,18 +98,30 @@ LUAAPI(vec2_newZero) {
return 1;
}

static const luaL_Reg lua_reg_vec2_c[11] = {
{"new", lua_api_vec2_new },
{"newLowest", lua_api_vec2_newLowest },
{"newMax", lua_api_vec2_newMax },
{"newMin", lua_api_vec2_newMin },
{"newNegUnitX", lua_api_vec2_newNegUnitX},
{"newNegUnitY", lua_api_vec2_newNegUnitY},
{"newOne", lua_api_vec2_newOne },
{"newUnitX", lua_api_vec2_newUnitX },
{"newUnitY", lua_api_vec2_newUnitY },
{"newZero", lua_api_vec2_newZero },
{NULL, NULL }
LUAAPI(vec2_newFromDirection) {
LUA_ARG_COUNT_CHECK_C(1)
Vec3* pos = (Vec3*)luaL_checkudata(L, 1, "vec3_mt");
luaL_argcheck(L, pos != nullptr, 1, "invalid userdata");
lua_settop(L, 0);
Vec2* rot = (Vec2*)lua_newuserdata(L, sizeof(Vec2));
*rot = Vec3::rotationFromDirection(*pos);
luaL_setmetatable(L, "vec2_mt");
return 1;
}

static const luaL_Reg lua_reg_vec2_c[12] = {
{"new", lua_api_vec2_new },
{"newLowest", lua_api_vec2_newLowest },
{"newMax", lua_api_vec2_newMax },
{"newMin", lua_api_vec2_newMin },
{"newNegUnitX", lua_api_vec2_newNegUnitX },
{"newNegUnitY", lua_api_vec2_newNegUnitY },
{"newOne", lua_api_vec2_newOne },
{"newUnitX", lua_api_vec2_newUnitX },
{"newUnitY", lua_api_vec2_newUnitY },
{"newZero", lua_api_vec2_newZero },
{"newFromDirection", lua_api_vec2_newFromDirection},
{NULL, NULL }
};

LUAAPI(vec2_get) {
Expand Down
4 changes: 3 additions & 1 deletion src/cfsp/simplayer/luaapi/Vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ int lua_api_vec2_newUnitY(lua_State*);

int lua_api_vec2_newZero(lua_State*);

extern const luaL_Reg lua_reg_vec2_c[11];
int lua_api_vec2_newFromDirection(lua_State*);

extern const luaL_Reg lua_reg_vec2_c[12];

int lua_api_vec2_get(lua_State*);

Expand Down
42 changes: 27 additions & 15 deletions src/cfsp/simplayer/luaapi/Vec3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,33 @@ LUAAPI(vec3_newZero) {
return 1;
}

const luaL_Reg lua_reg_vec3_c[14] = {
{"new", lua_api_vec3_new },
{"newHalf", lua_api_vec3_newHalf },
{"newMax", lua_api_vec3_newMax },
{"newMin", lua_api_vec3_newMin },
{"newNegUnitX", lua_api_vec3_newNegUnitX},
{"newNegUnitY", lua_api_vec3_newNegUnitY},
{"newNegUnitZ", lua_api_vec3_newNegUnitZ},
{"newOne", lua_api_vec3_newOne },
{"newTwo", lua_api_vec3_newTwo },
{"newUnitX", lua_api_vec3_newUnitX },
{"newUnitY", lua_api_vec3_newUnitY },
{"newUnitZ", lua_api_vec3_newUnitZ },
{"newZero", lua_api_vec3_newZero },
{NULL, NULL }
LUAAPI(vec3_newFromRotation) {
LUA_ARG_COUNT_CHECK_C(1)
Vec2* rot = (Vec2*)luaL_checkudata(L, 1, "vec2_mt");
luaL_argcheck(L, rot != nullptr, 1, "invalid userdata");
lua_settop(L, 0);
Vec3* pos = (Vec3*)lua_newuserdata(L, sizeof(Vec3));
*pos = Vec3::directionFromRotation(*rot);
luaL_setmetatable(L, "vec3_mt");
return 1;
}

const luaL_Reg lua_reg_vec3_c[15] = {
{"new", lua_api_vec3_new },
{"newHalf", lua_api_vec3_newHalf },
{"newMax", lua_api_vec3_newMax },
{"newMin", lua_api_vec3_newMin },
{"newNegUnitX", lua_api_vec3_newNegUnitX },
{"newNegUnitY", lua_api_vec3_newNegUnitY },
{"newNegUnitZ", lua_api_vec3_newNegUnitZ },
{"newOne", lua_api_vec3_newOne },
{"newTwo", lua_api_vec3_newTwo },
{"newUnitX", lua_api_vec3_newUnitX },
{"newUnitY", lua_api_vec3_newUnitY },
{"newUnitZ", lua_api_vec3_newUnitZ },
{"newZero", lua_api_vec3_newZero },
{"newFromRotation", lua_api_vec3_newFromRotation},
{NULL, NULL }
};

LUAAPI(vec3_get) {
Expand Down
4 changes: 3 additions & 1 deletion src/cfsp/simplayer/luaapi/Vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ int lua_api_vec3_newUnitZ(lua_State*);

int lua_api_vec3_newZero(lua_State*);

extern const luaL_Reg lua_reg_vec3_c[14];
int lua_api_vec3_newFromRotation(lua_State*);

extern const luaL_Reg lua_reg_vec3_c[15];

int lua_api_vec3_get(lua_State*);

Expand Down

0 comments on commit 85b3c43

Please sign in to comment.