freedreno/decode: Replace/remove __tonumber()

This was never actually implemented by lua.  Remove it.  In the case of
enums, implement the __eq() function instead so enum values can be
compared for equality.

Signed-off-by: Rob Clark <rob.clark@oss.qualcomm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39573>
This commit is contained in:
Rob Clark 2026-01-27 13:53:20 -08:00 committed by Marge Bot
parent cdb8c6a14c
commit 6d7a056c8b

View file

@ -84,6 +84,7 @@ error(const char *fmt)
*/
struct rnndenum {
struct rnnenum *e;
const char *str;
int val;
};
@ -102,20 +103,21 @@ l_meta_rnn_enum_tostring(lua_State *L)
return 1;
}
/* so, this doesn't actually seem to be implemented yet, but hopefully
* some day lua comes to it's senses
*/
static int
l_meta_rnn_enum_tonumber(lua_State *L)
l_meta_rnn_enum_eq(lua_State *L)
{
struct rnndenum *e = lua_touserdata(L, 1);
lua_pushinteger(L, e->val);
struct rnndenum *e1 = lua_touserdata(L, 1);
struct rnndenum *e2 = lua_touserdata(L, 2);
/* Do the enum type+value match: */
lua_pushboolean(L, (e1->e == e2->e) && (e1->val == e2->val));
return 1;
}
static const struct luaL_Reg l_meta_rnn_enum[] = {
{"__tostring", l_meta_rnn_enum_tostring},
{"__tonumber", l_meta_rnn_enum_tonumber},
{"__eq", l_meta_rnn_enum_eq},
{NULL, NULL} /* sentinel */
};
@ -124,6 +126,7 @@ pushenum(struct lua_State *L, struct rnn *rnn, int val, struct rnnenum *info)
{
struct rnndenum *e = lua_newuserdata(L, sizeof(*e));
e->e = info;
e->val = val;
e->str = rnn_enumname(rnn, info->name, val);
@ -377,22 +380,9 @@ l_rnn_reg_meta_tostring(lua_State *L)
return 1;
}
static int
l_rnn_reg_meta_tonumber(lua_State *L)
{
struct rnndoff *rnndoff = lua_touserdata(L, 1);
uint32_t regval = rnn_val(rnndoff->rnn, rnndoff->offset);
regval <<= rnndoff->elem->typeinfo.shr;
lua_pushnumber(L, regval);
return 1;
}
static const struct luaL_Reg l_meta_rnn_reg[] = {
{"__index", l_rnn_reg_meta_index},
{"__tostring", l_rnn_reg_meta_tostring},
{"__tonumber", l_rnn_reg_meta_tonumber},
{NULL, NULL} /* sentinel */
};