From 7cdad52fb8667688ecaf864026f5d80707b0b9be Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:28:28 +1000 Subject: [PATCH] print type names rather than their type index --- src/pc/lua/smlua_functions.c | 8 ++++---- src/pc/lua/smlua_hooks.c | 6 +++--- src/pc/lua/smlua_utils.c | 22 +++++++++++----------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/pc/lua/smlua_functions.c b/src/pc/lua/smlua_functions.c index d06a6a825..91133086b 100644 --- a/src/pc/lua/smlua_functions.c +++ b/src/pc/lua/smlua_functions.c @@ -99,7 +99,7 @@ int smlua_func_network_init_object(lua_State* L) { if (!gSmLuaConvertSuccess) { LOG_LUA("network_init_object: Failed to convert parameter 2"); return 0; } if (lua_type(L, 3) != LUA_TNIL && lua_type(L, 3) != LUA_TTABLE) { - LOG_LUA_LINE("network_init_object() called with an invalid type for param 3: %u", lua_type(L, 3)); + LOG_LUA_LINE("network_init_object() called with an invalid type for param 3: %s", luaL_typename(L, 3)); return 0; } @@ -115,7 +115,7 @@ int smlua_func_network_init_object(lua_State* L) { while (lua_next(L, 3) != 0) { // uses 'key' (at index -2) and 'value' (at index -1) if (lua_type(L, -1) != LUA_TSTRING) { - LOG_LUA_LINE("Invalid type passed to network_init_object(): %u", lua_type(L, -1)); + LOG_LUA_LINE("Invalid type passed to network_init_object(): %s", luaL_typename(L, -1)); lua_pop(L, 1); // pop value continue; } @@ -189,7 +189,7 @@ int smlua_func_set_exclamation_box_contents(lua_State* L) { if (!smlua_functions_valid_param_count(L, 1)) { return 0; } if (lua_type(L, 1) != LUA_TTABLE) { - LOG_LUA_LINE("Invalid type passed to set_exclamation_box(): %u", lua_type(L, -1)); + LOG_LUA_LINE("Invalid type passed to set_exclamation_box(): %s", luaL_typename(L, -1)); return 0; } @@ -297,7 +297,7 @@ int smlua_func_get_texture_info(lua_State* L) { if (!smlua_functions_valid_param_count(L, 1)) { return 0; } if (lua_type(L, -1) != LUA_TSTRING) { - LOG_LUA_LINE("Invalid type passed to get_texture_info(): %u", lua_type(L, -1)); + LOG_LUA_LINE("Invalid type passed to get_texture_info(): %s", luaL_typename(L, -1)); lua_pop(L, 1); // pop value return 0; } diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 0c9863221..fadc0187e 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -1170,7 +1170,7 @@ int smlua_hook_mario_action(lua_State* L) { bool oldApi = secondParamType == LUA_TFUNCTION; if (!oldApi && secondParamType != LUA_TTABLE) { - LOG_LUA_LINE("smlua_hook_mario_action received improper type '%d'", lua_type(L, 2)); + LOG_LUA_LINE("smlua_hook_mario_action received improper type '%s'", luaL_typename(L, 2)); return 0; } @@ -1937,12 +1937,12 @@ int smlua_hook_on_sync_table_change(lua_State* L) { } if (lua_type(L, syncTableIndex) != LUA_TTABLE) { - LOG_LUA_LINE("Tried to attach a non-table to hook_on_sync_table_change: %d", lua_type(L, syncTableIndex)); + LOG_LUA_LINE("Tried to attach a non-table to hook_on_sync_table_change: %s", luaL_typename(L, syncTableIndex)); return 0; } if (lua_type(L, funcIndex) != LUA_TFUNCTION) { - LOG_LUA_LINE("Tried to attach a non-function to hook_on_sync_table_change: %d", lua_type(L, funcIndex)); + LOG_LUA_LINE("Tried to attach a non-function to hook_on_sync_table_change: %s", luaL_typename(L, funcIndex)); return 0; } diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index 4cdec544a..19e5ebc9f 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -84,7 +84,7 @@ bool smlua_is_table_empty(int index) { bool smlua_to_boolean(lua_State* L, int index) { if (lua_type(L, index) != LUA_TBOOLEAN) { - LOG_LUA_LINE("smlua_to_boolean received improper type '%d'", lua_type(L, index)); + LOG_LUA_LINE("smlua_to_boolean received improper type '%s'", luaL_typename(L, index)); gSmLuaConvertSuccess = false; return 0; } @@ -96,7 +96,7 @@ lua_Integer smlua_to_integer(lua_State* L, int index) { gSmLuaConvertSuccess = true; return lua_toboolean(L, index) ? 1 : 0; } else if (lua_type(L, index) != LUA_TNUMBER) { - LOG_LUA_LINE("smlua_to_integer received improper type '%d'", lua_type(L, index)); + LOG_LUA_LINE("smlua_to_integer received improper type '%s'", luaL_typename(L, index)); gSmLuaConvertSuccess = false; return 0; } @@ -110,7 +110,7 @@ lua_Number smlua_to_number(lua_State* L, int index) { gSmLuaConvertSuccess = true; return lua_toboolean(L, index) ? 1 : 0; } else if (lua_type(L, index) != LUA_TNUMBER) { - LOG_LUA_LINE("smlua_to_number received improper type '%d'", lua_type(L, index)); + LOG_LUA_LINE("smlua_to_number received improper type '%s'", luaL_typename(L, index)); gSmLuaConvertSuccess = false; return 0; } @@ -120,7 +120,7 @@ lua_Number smlua_to_number(lua_State* L, int index) { const char* smlua_to_string(lua_State* L, int index) { if (lua_type(L, index) != LUA_TSTRING) { - LOG_LUA_LINE("smlua_to_string received improper type '%d'", lua_type(L, index)); + LOG_LUA_LINE("smlua_to_string received improper type '%s'", luaL_typename(L, index)); gSmLuaConvertSuccess = false; return 0; } @@ -134,7 +134,7 @@ LuaFunction smlua_to_lua_function(lua_State* L, int index) { } if (lua_type(L, index) != LUA_TFUNCTION) { - LOG_LUA_LINE("smlua_to_lua_function received improper type '%d'", lua_type(L, index)); + LOG_LUA_LINE("smlua_to_lua_function received improper type '%s'", luaL_typename(L, index)); gSmLuaConvertSuccess = false; return 0; } @@ -151,7 +151,7 @@ bool smlua_is_cobject(lua_State* L, int index, UNUSED u16 lot) { void* smlua_to_cobject(lua_State* L, int index, u16 lot) { s32 indexType = lua_type(L, index); if (indexType != LUA_TUSERDATA) { - LOG_LUA_LINE("smlua_to_cobject received improper type '%d'", indexType); + LOG_LUA_LINE("smlua_to_cobject received improper type '%s'", lua_typename(L, indexType)); gSmLuaConvertSuccess = false; return 0; } @@ -177,7 +177,7 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) { void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) { s32 indexType = lua_type(L, index); if (indexType != LUA_TUSERDATA) { - LOG_LUA_LINE("smlua_to_cpointer received improper type '%d'", indexType); + LOG_LUA_LINE("smlua_to_cpointer received improper type '%s'", lua_typename(L, indexType)); gSmLuaConvertSuccess = false; return 0; } @@ -468,7 +468,7 @@ void smlua_push_lnt(struct LSTNetworkType* lnt) { lua_Integer smlua_get_integer_field(int index, const char* name) { if (lua_type(gLuaState, index) != LUA_TTABLE && lua_type(gLuaState, index) != LUA_TUSERDATA) { - LOG_LUA_LINE("smlua_get_integer_field received improper type '%d'", lua_type(gLuaState, index)); + LOG_LUA_LINE("smlua_get_integer_field received improper type '%s'", luaL_typename(gLuaState, index)); gSmLuaConvertSuccess = false; return 0; } @@ -480,7 +480,7 @@ lua_Integer smlua_get_integer_field(int index, const char* name) { lua_Number smlua_get_number_field(int index, const char* name) { if (lua_type(gLuaState, index) != LUA_TTABLE && lua_type(gLuaState, index) != LUA_TUSERDATA) { - LOG_LUA_LINE("smlua_get_number_field received improper type '%d'", lua_type(gLuaState, index)); + LOG_LUA_LINE("smlua_get_number_field received improper type '%s'", luaL_typename(gLuaState, index)); gSmLuaConvertSuccess = false; return 0; } @@ -492,7 +492,7 @@ lua_Number smlua_get_number_field(int index, const char* name) { const char* smlua_get_string_field(int index, const char* name) { if (lua_type(gLuaState, index) != LUA_TTABLE && lua_type(gLuaState, index) != LUA_TUSERDATA) { - LOG_LUA_LINE("smlua_get_string_field received improper type '%d'", lua_type(gLuaState, index)); + LOG_LUA_LINE("smlua_get_string_field received improper type '%s'", luaL_typename(gLuaState, index)); gSmLuaConvertSuccess = false; return 0; } @@ -504,7 +504,7 @@ const char* smlua_get_string_field(int index, const char* name) { LuaFunction smlua_get_function_field(int index, const char *name) { if (lua_type(gLuaState, index) != LUA_TTABLE && lua_type(gLuaState, index) != LUA_TUSERDATA) { - LOG_LUA_LINE("smlua_get_function_field received improper type '%d'", lua_type(gLuaState, index)); + LOG_LUA_LINE("smlua_get_function_field received improper type '%s'", luaL_typename(gLuaState, index)); gSmLuaConvertSuccess = false; return 0; }