Skip to content

Commit

Permalink
lua: use common way to assign metatables to vecN userdata types
Browse files Browse the repository at this point in the history
progress #304
  • Loading branch information
alexey-lysiuk committed Dec 25, 2024
1 parent 4588a88 commit 6eb81ba
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions Quake/ls_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,6 @@ static int LS_value_vector_tostring(lua_State* state)
template <size_t N>
int LS_PushVectorValue(lua_State* state, const LS_Vector<N>& value)
{
const auto& userdatatype = LS_GetVectorUserDataType<N>();

LS_Vector<N>& newvalue = userdatatype.New(state);
newvalue = value;

// Create and set 'vecN' metatable
static const luaL_Reg functions[] =
{
// Math functions
Expand All @@ -274,13 +268,12 @@ int LS_PushVectorValue(lua_State* state, const LS_Vector<N>& value)
{ "__index", LS_value_vector_index<N> },
{ "__newindex", LS_value_vector_newindex<N> },
{ "__tostring", LS_value_vector_tostring<N> },
{ NULL, NULL }
{ nullptr, nullptr }
};

if (luaL_newmetatable(state, userdatatype.GetName()))
luaL_setfuncs(state, functions, 0);
const auto& userdatatype = LS_GetVectorUserDataType<N>();
userdatatype.New(state, nullptr, functions) = value;

lua_setmetatable(state, -2);
return 1;
}

Expand Down

0 comments on commit 6eb81ba

Please sign in to comment.