From a9429caf099eb91c0506e33adb9e4853016a4811 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 17 Feb 2025 14:21:44 +0300 Subject: [PATCH] Fix "attempt to perform arithmetic on a number value" errors Not best fix but i don't know why setnumV breaks here --- src/bluajit/lib_table.c | 6 +++++- src/bluajit/lj_carith.c | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bluajit/lib_table.c b/src/bluajit/lib_table.c index 97ba2847e..c1b6e40fa 100644 --- a/src/bluajit/lib_table.c +++ b/src/bluajit/lib_table.c @@ -9,6 +9,8 @@ #define lib_table_c #define LUA_LIB +#include "../console.h" + #include "lua.h" #include "lauxlib.h" #include "lualib.h" @@ -72,7 +74,9 @@ LJLIB_CF(table_maxn) lua_Number n = numberVnum(&node[i].key); if (n > m) m = n; } - setnumV(L->top-1, m); + /* This should be setnumV but for some reason it makes numbers broken, + * which causes "attempt to perform arithmetic on a number value" errors */ + setintV(L->top-1, m); return 1; } diff --git a/src/bluajit/lj_carith.c b/src/bluajit/lj_carith.c index ffda626e1..ed8fff31f 100644 --- a/src/bluajit/lj_carith.c +++ b/src/bluajit/lj_carith.c @@ -249,11 +249,11 @@ static int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm) } for (i = 0; i < 2; i++) { if (ca->ct[i] && tviscdata(L->base+i)) { - if (ctype_isenum(ca->ct[i]->info)) isenum = i; - repr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL)); + if (ctype_isenum(ca->ct[i]->info)) isenum = i; + repr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL)); } else { - if (tvisstr(&L->base[i])) isstr = i; - repr[i] = lj_typename(&L->base[i]); + if (tvisstr(&L->base[i])) isstr = i; + repr[i] = lj_typename(&L->base[i]); } } if ((isenum ^ isstr) == 1)