Skip to content

Commit

Permalink
lua: use table for __index metavalue of progs function parameter us…
Browse files Browse the repository at this point in the history
…erdata
  • Loading branch information
alexey-lysiuk committed Aug 17, 2024
1 parent efd7058 commit 2a66637
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions Quake/ls_progs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,6 @@ static int LS_value_functionparameter_type(lua_State* state)
return 1;
}

constexpr LS_Member ls_functionparameter_members[] =
{
{ "name", LS_value_functionparameter_name },
{ "type", LS_value_functionparameter_type },
};

// Pushes method of 'function parameter' userdata by its name
static int LS_value_functionparameter_index(lua_State* state)
{
return LS_GetMember(state, ls_functionparameter_type, ls_functionparameter_members, Q_COUNTOF(ls_functionparameter_members));
}

// Pushes string representation of given 'function parameter' userdata
static int LS_value_functionparameter_tostring(lua_State* state)
{
Expand All @@ -276,15 +264,22 @@ static int LS_value_functionparameter_tostring(lua_State* state)
// Sets metatable for 'function parameter' userdata
static void LS_SetFunctionParameterMetaTable(lua_State* state)
{
static const luaL_Reg functions[] =
if (luaL_newmetatable(state, "funcparam"))
{
{ "__index", LS_value_functionparameter_index },
{ "__tostring", LS_value_functionparameter_tostring },
{ NULL, NULL }
};
lua_pushcfunction(state, LS_value_functionparameter_tostring);
lua_setfield(state, -2, "__tostring");

if (luaL_newmetatable(state, "funcparam"))
static const luaL_Reg functions[] =
{
{ "name", LS_value_functionparameter_name },
{ "type", LS_value_functionparameter_type },
{ nullptr, nullptr }
};

lua_createtable(state, 0, 2);
luaL_setfuncs(state, functions, 0);
lua_setfield(state, -2, "__index");
}

lua_setmetatable(state, -2);
}
Expand Down

0 comments on commit 2a66637

Please sign in to comment.