mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-01-07 08:01:16 +00:00
Made Lua errors show a backtrace for almost all cases
This commit is contained in:
parent
ba544d6e35
commit
174e3d97ed
11 changed files with 144 additions and 220 deletions
|
@ -22,11 +22,28 @@ void smlua_mod_error(void) {
|
|||
djui_lua_error(txt);
|
||||
}
|
||||
|
||||
int smlua_error_handler(UNUSED lua_State* L) {
|
||||
if (lua_type(L, -1) == LUA_TSTRING) {
|
||||
LOG_LUA("%s", lua_tostring(L, -1));
|
||||
}
|
||||
smlua_logline();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int smlua_pcall(lua_State* L, int nargs, int nresults, UNUSED int errfunc) {
|
||||
lua_pushcfunction(L, smlua_error_handler);
|
||||
int errorHandlerIndex = 1;
|
||||
lua_insert(L, errorHandlerIndex);
|
||||
int rc = lua_pcall(L, nargs, nresults, errorHandlerIndex);
|
||||
lua_remove(L, errorHandlerIndex);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void smlua_exec_file(char* path) {
|
||||
lua_State* L = gLuaState;
|
||||
if (luaL_dofile(L, path) != LUA_OK) {
|
||||
LOG_LUA("Failed to load lua file '%s'.", path);
|
||||
puts(smlua_to_string(L, lua_gettop(L)));
|
||||
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));
|
||||
}
|
||||
lua_pop(L, lua_gettop(L));
|
||||
}
|
||||
|
@ -35,7 +52,7 @@ static void smlua_exec_str(char* str) {
|
|||
lua_State* L = gLuaState;
|
||||
if (luaL_dostring(L, str) != LUA_OK) {
|
||||
LOG_LUA("Failed to load lua string.");
|
||||
puts(smlua_to_string(L, lua_gettop(L)));
|
||||
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));
|
||||
}
|
||||
lua_pop(L, lua_gettop(L));
|
||||
}
|
||||
|
@ -46,7 +63,7 @@ static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteI
|
|||
gLuaInitializingScript = 1;
|
||||
if (luaL_loadfile(L, file->cachedPath) != LUA_OK) {
|
||||
LOG_LUA("Failed to load lua script '%s'.", file->cachedPath);
|
||||
puts(smlua_to_string(L, lua_gettop(L)));
|
||||
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -87,9 +104,9 @@ static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteI
|
|||
}
|
||||
|
||||
// run chunks
|
||||
if (lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) {
|
||||
if (smlua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) {
|
||||
LOG_LUA("Failed to execute lua script '%s'.", file->cachedPath);
|
||||
puts(smlua_to_string(L, lua_gettop(L)));
|
||||
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));
|
||||
smlua_dump_stack();
|
||||
gLuaInitializingScript = 0;
|
||||
return;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "pc/debuglog.h"
|
||||
|
||||
#define LOG_LUA(...) { if (!gSmLuaSuppressErrors) { _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n"), smlua_mod_error(); } }
|
||||
#define LOG_LUA_LINE(...) { if (!gSmLuaSuppressErrors) { _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n"), smlua_mod_error(); smlua_logline(); } }
|
||||
|
||||
#ifdef DEVELOPMENT
|
||||
#define LUA_STACK_CHECK_BEGIN() int __LUA_STACK_TOP = lua_gettop(gLuaState)
|
||||
|
@ -37,6 +38,8 @@ extern struct Mod* gLuaActiveMod;
|
|||
extern struct Mod* gLuaLastHookMod;
|
||||
|
||||
void smlua_mod_error(void);
|
||||
int smlua_error_handler(UNUSED lua_State* L);
|
||||
int smlua_pcall(lua_State* L, int nargs, int nresults, int errfunc);
|
||||
|
||||
void smlua_init(void);
|
||||
void smlua_update(void);
|
||||
|
|
|
@ -130,12 +130,12 @@ static int smlua_func_define_custom_obj_fields(lua_State* L) {
|
|||
if (!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
if (lua_type(L, 1) != LUA_TTABLE) {
|
||||
LOG_LUA("Invalid parameter for define_custom_obj_fields()");
|
||||
LOG_LUA_LINE("Invalid parameter for define_custom_obj_fields()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("define_custom_obj_fields() can only be called on load.");
|
||||
LOG_LUA_LINE("define_custom_obj_fields() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -160,25 +160,25 @@ static int smlua_func_define_custom_obj_fields(lua_State* L) {
|
|||
int valueIndex = lua_gettop(L) - 0;
|
||||
// uses 'key' (at index -2) and 'value' (at index -1)
|
||||
if (lua_type(L, keyIndex) != LUA_TSTRING) {
|
||||
LOG_LUA("Invalid key type for define_custom_obj_fields() : %u", lua_type(L, keyIndex));
|
||||
LOG_LUA_LINE("Invalid key type for define_custom_obj_fields() : %u", lua_type(L, keyIndex));
|
||||
lua_settop(L, iterationTop);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lua_type(L, valueIndex) != LUA_TSTRING) {
|
||||
LOG_LUA("Invalid value type for define_custom_obj_fields() : %u", lua_type(L, valueIndex));
|
||||
LOG_LUA_LINE("Invalid value type for define_custom_obj_fields() : %u", lua_type(L, valueIndex));
|
||||
lua_settop(L, iterationTop);
|
||||
continue;
|
||||
}
|
||||
|
||||
const char* key = smlua_to_string(L, keyIndex);
|
||||
if (key[0] != 'o') {
|
||||
LOG_LUA("Invalid key name for define_custom_obj_fields()");
|
||||
LOG_LUA_LINE("Invalid key name for define_custom_obj_fields()");
|
||||
lua_settop(L, iterationTop);
|
||||
continue;
|
||||
}
|
||||
if (strlen(key) >= CUSTOM_FIELD_ITEM_LEN) {
|
||||
LOG_LUA("Too long of key name for define_custom_obj_fields()");
|
||||
LOG_LUA_LINE("Too long of key name for define_custom_obj_fields()");
|
||||
lua_settop(L, iterationTop);
|
||||
continue;
|
||||
}
|
||||
|
@ -189,12 +189,12 @@ static int smlua_func_define_custom_obj_fields(lua_State* L) {
|
|||
else if (!strcmp(value, "s32")) { lvt = LVT_S32; }
|
||||
else if (!strcmp(value, "f32")) { lvt = LVT_F32; }
|
||||
else {
|
||||
LOG_LUA("Invalid value name for define_custom_obj_fields()");
|
||||
LOG_LUA_LINE("Invalid value name for define_custom_obj_fields()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (customFieldCount >= CUSTOM_FIELD_MAX) {
|
||||
LOG_LUA("Ran out of custom fields!");
|
||||
LOG_LUA_LINE("Ran out of custom fields!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ static int smlua_func_define_custom_obj_fields(lua_State* L) {
|
|||
} else if (fieldIndex > 0x22 && fieldIndex < 0x48) {
|
||||
fieldIndex = 0x48;
|
||||
} else if (fieldIndex > 0x4A) {
|
||||
LOG_LUA("Ran out of custom fields!");
|
||||
LOG_LUA_LINE("Ran out of custom fields!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ struct LuaObjectField* smlua_get_custom_field(lua_State* L, u32 lot, int keyInde
|
|||
if (lot != LOT_OBJECT) { return NULL; }
|
||||
|
||||
if (gLuaActiveMod == NULL) {
|
||||
LOG_LUA("Failed to retrieve active mod entry.");
|
||||
LOG_LUA_LINE("Failed to retrieve active mod entry.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -333,20 +333,17 @@ static int smlua__get_field(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
if (pointer == 0) {
|
||||
LOG_LUA("_get_field on null pointer");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_get_field on null pointer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!smlua_valid_lot(lot)) {
|
||||
LOG_LUA("_get_field on invalid LOT '%u'", lot);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_get_field on invalid LOT '%u'", lot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!smlua_cobject_allowlist_contains(lot, pointer)) {
|
||||
LOG_LUA("_get_field received a pointer not in allow list. '%u', '%llu", lot, (u64)pointer);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_get_field received a pointer not in allow list. '%u', '%llu", lot, (u64)pointer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -355,8 +352,7 @@ static int smlua__get_field(lua_State* L) {
|
|||
data = smlua_get_custom_field(L, lot, 3);
|
||||
}
|
||||
if (data == NULL) {
|
||||
LOG_LUA("_get_field on invalid key '%s', lot '%d'", key, lot);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_get_field on invalid key '%s', lot '%d'", key, lot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -399,8 +395,7 @@ static int smlua__get_field(lua_State* L) {
|
|||
break;
|
||||
|
||||
default:
|
||||
LOG_LUA("_get_field on unimplemented type '%d', key '%s'", data->valueType, key);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_get_field on unimplemented type '%d', key '%s'", data->valueType, key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -421,20 +416,17 @@ static int smlua__set_field(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
if (pointer == 0) {
|
||||
LOG_LUA("_set_field on null pointer");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_set_field on null pointer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!smlua_valid_lot(lot)) {
|
||||
LOG_LUA("_set_field on invalid LOT '%u'", lot);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_set_field on invalid LOT '%u'", lot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!smlua_cobject_allowlist_contains(lot, pointer)) {
|
||||
LOG_LUA("_set_field received a pointer not in allow list. '%u', '%llu", lot, (u64)pointer);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_set_field received a pointer not in allow list. '%u', '%llu", lot, (u64)pointer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -444,14 +436,12 @@ static int smlua__set_field(lua_State* L) {
|
|||
}
|
||||
|
||||
if (data == NULL) {
|
||||
LOG_LUA("_set_field on invalid key '%s'", key);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_set_field on invalid key '%s'", key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (data->immutable) {
|
||||
LOG_LUA("_set_field on immutable key '%s'", key);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_set_field on immutable key '%s'", key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -493,13 +483,11 @@ static int smlua__set_field(lua_State* L) {
|
|||
break;
|
||||
|
||||
default:
|
||||
LOG_LUA("_set_field on unimplemented type '%d', key '%s'", data->valueType, key);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_set_field on unimplemented type '%d', key '%s'", data->valueType, key);
|
||||
return 0;
|
||||
}
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("_set_field failed to retrieve value type '%d', key '%s'", data->valueType, key);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("_set_field failed to retrieve value type '%d', key '%s'", data->valueType, key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
bool smlua_functions_valid_param_count(lua_State* L, int expected) {
|
||||
int top = lua_gettop(L);
|
||||
if (top != expected) {
|
||||
LOG_LUA("improper param count: expected %u, received %u", expected, top);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("improper param count: expected %u, received %u", expected, top);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -23,8 +22,7 @@ bool smlua_functions_valid_param_count(lua_State* L, int expected) {
|
|||
bool smlua_functions_valid_param_range(lua_State* L, int min, int max) {
|
||||
int top = lua_gettop(L);
|
||||
if (top < min || top > max) {
|
||||
LOG_LUA("improper param count: expected (%u - %u), received %u", min, max, top);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("improper param count: expected (%u - %u), received %u", min, max, top);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -68,7 +66,7 @@ int smlua_func_atan2s(lua_State* L) {
|
|||
|
||||
int smlua_func_init_mario_after_warp(lua_State* L) {
|
||||
if (network_player_connected_count() >= 2) {
|
||||
LOG_LUA("This function can only be used in single-player");
|
||||
LOG_LUA_LINE("This function can only be used in single-player");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -82,7 +80,7 @@ int smlua_func_init_mario_after_warp(lua_State* L) {
|
|||
|
||||
int smlua_func_reset_level(lua_State* L) {
|
||||
if (network_player_connected_count() >= 2) {
|
||||
LOG_LUA("This function can only be used in single-player");
|
||||
LOG_LUA_LINE("This function can only be used in single-player");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -103,13 +101,13 @@ int smlua_func_network_init_object(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
if (lua_type(L, 3) != LUA_TNIL && lua_type(L, 3) != LUA_TTABLE) {
|
||||
LOG_LUA("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: %u", lua_type(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct SyncObject* so = network_init_object(obj, standardSync ? 4000.0f : SYNC_DISTANCE_ONLY_EVENTS);
|
||||
if (so == NULL) {
|
||||
LOG_LUA("Failed to allocate sync object.");
|
||||
LOG_LUA_LINE("Failed to allocate sync object.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -119,13 +117,13 @@ 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("Invalid type passed to network_init_object(): %u", lua_type(L, -1));
|
||||
LOG_LUA_LINE("Invalid type passed to network_init_object(): %u", lua_type(L, -1));
|
||||
lua_pop(L, 1); // pop value
|
||||
continue;
|
||||
}
|
||||
const char* fieldIdentifier = smlua_to_string(L, -1);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Invalid field passed to network_init_object()");
|
||||
LOG_LUA_LINE("Invalid field passed to network_init_object()");
|
||||
lua_pop(L, 1); // pop value
|
||||
continue;
|
||||
}
|
||||
|
@ -141,7 +139,7 @@ int smlua_func_network_init_object(lua_State* L) {
|
|||
if ((data->valueType == LVT_U8) || (data->valueType == LVT_S8)) { lvtSize = 8; }
|
||||
|
||||
if (data == NULL || lvtSize == 0) {
|
||||
LOG_LUA("Invalid field passed to network_init_object(): %s", fieldIdentifier);
|
||||
LOG_LUA_LINE("Invalid field passed to network_init_object(): %s", fieldIdentifier);
|
||||
lua_pop(L, 1); // pop value
|
||||
continue;
|
||||
}
|
||||
|
@ -167,7 +165,7 @@ int smlua_func_network_send_object(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
if (obj->oSyncID == 0 || gSyncObjects[obj->oSyncID].o != obj) {
|
||||
LOG_LUA("Failed to retrieve sync object.");
|
||||
LOG_LUA_LINE("Failed to retrieve sync object.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ static int smlua_call_hook(lua_State* L, int nargs, int nresults, int errfunc, s
|
|||
#if defined(LUA_PROFILER)
|
||||
lua_profiler_start_counter(activeMod);
|
||||
#endif
|
||||
int rc = lua_pcall(L, nargs, nresults, errfunc);
|
||||
int rc = smlua_pcall(L, nargs, nresults, errfunc);
|
||||
#if defined(LUA_PROFILER)
|
||||
lua_profiler_stop_counter(activeMod);
|
||||
#endif
|
||||
|
@ -107,22 +107,19 @@ int smlua_hook_event(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
if (hookType >= HOOK_MAX) {
|
||||
LOG_LUA("Hook Type: %d exceeds max!", hookType);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook Type: %d exceeds max!", hookType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
|
||||
if (hook->count >= MAX_HOOKED_REFERENCES) {
|
||||
LOG_LUA("Hook Type: %s exceeded maximum references!", LuaHookedEventTypeName[hookType]);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook Type: %s exceeded maximum references!", LuaHookedEventTypeName[hookType]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
if (ref == -1) {
|
||||
LOG_LUA("tried to hook undefined function to '%s'", LuaHookedEventTypeName[hookType]);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("tried to hook undefined function to '%s'", LuaHookedEventTypeName[hookType]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -143,8 +140,7 @@ void smlua_call_event_hooks(enum LuaHookedEventType hookType) {
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the event_hook callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the event_hook callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +159,7 @@ void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool va
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -185,8 +180,7 @@ void smlua_call_event_hooks_bool_param_ret_bool(enum LuaHookedEventType hookType
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -214,8 +208,7 @@ void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -239,8 +232,7 @@ void smlua_call_event_hooks_mario_param_ret_bool(enum LuaHookedEventType hookTyp
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -274,8 +266,7 @@ void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struc
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -305,8 +296,7 @@ void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookTy
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -343,8 +333,7 @@ void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, st
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 4, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -363,8 +352,7 @@ void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struc
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -382,8 +370,7 @@ bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* retur
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 0, 1, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -413,8 +400,7 @@ void smlua_call_event_hooks_network_player_param(enum LuaHookedEventType hookTyp
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -439,8 +425,7 @@ void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookT
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -466,8 +451,7 @@ void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int mo
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -495,22 +479,20 @@ int smlua_hook_mario_action(lua_State* L) {
|
|||
if (!smlua_functions_valid_param_range(L, 2, 3)) { return 0; }
|
||||
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_mario_action() can only be called on load.");
|
||||
LOG_LUA_LINE("hook_mario_action() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int paramCount = lua_gettop(L);
|
||||
|
||||
if (sHookedMarioActionsCount >= MAX_HOOKED_ACTIONS) {
|
||||
LOG_LUA("Hooked mario actions exceeded maximum references!");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hooked mario actions exceeded maximum references!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_Integer action = smlua_to_integer(L, 1);
|
||||
if (action == 0 || !gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Hook Action: tried to hook invalid action: %lld, %u", action, gSmLuaConvertSuccess);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook Action: tried to hook invalid action: %lld, %u", action, gSmLuaConvertSuccess);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -518,8 +500,7 @@ int smlua_hook_mario_action(lua_State* L) {
|
|||
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
||||
if (ref == -1) {
|
||||
LOG_LUA("Hook Action: %lld tried to hook undefined function", action);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook Action: %lld tried to hook undefined function", action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -527,8 +508,7 @@ int smlua_hook_mario_action(lua_State* L) {
|
|||
if (paramCount >= 3) {
|
||||
interactionType = smlua_to_integer(L, 3);
|
||||
if (interactionType == 0 || !gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Hook Action: tried to hook invalid interactionType: %lld, %u", interactionType, gSmLuaConvertSuccess);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook Action: tried to hook invalid interactionType: %lld, %u", interactionType, gSmLuaConvertSuccess);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -561,8 +541,7 @@ bool smlua_call_action_hook(struct MarioState* m, s32* returnValue) {
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod)) {
|
||||
LOG_LUA("Failed to call the action callback: %u, %s", m->action, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the action callback: %u", m->action);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -650,13 +629,12 @@ int smlua_hook_behavior(lua_State* L) {
|
|||
if (!smlua_functions_valid_param_count(L, 5)) { return 0; }
|
||||
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_behavior() can only be called on load.");
|
||||
LOG_LUA_LINE("hook_behavior() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sHookedBehaviorsCount >= MAX_HOOKED_BEHAVIORS) {
|
||||
LOG_LUA("Hooked behaviors exceeded maximum references!");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hooked behaviors exceeded maximum references!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -664,22 +642,19 @@ int smlua_hook_behavior(lua_State* L) {
|
|||
gSmLuaConvertSuccess = true;
|
||||
lua_Integer overrideBehaviorId = noOverrideId ? 0xFFFFFF : smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Hook behavior: tried to override invalid behavior: %lld, %u", overrideBehaviorId, gSmLuaConvertSuccess);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook behavior: tried to override invalid behavior: %lld, %u", overrideBehaviorId, gSmLuaConvertSuccess);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_Integer objectList = smlua_to_integer(L, 2);
|
||||
if (objectList <= 0 || objectList >= NUM_OBJ_LISTS || !gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Hook behavior: tried use invalid object list: %lld, %u", objectList, gSmLuaConvertSuccess);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook behavior: tried use invalid object list: %lld, %u", objectList, gSmLuaConvertSuccess);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool replaceBehavior = smlua_to_boolean(L, 3);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Hook behavior: could not parse replaceBehavior");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook behavior: could not parse replaceBehavior");
|
||||
return 0;
|
||||
}
|
||||
const BehaviorScript* originalBehavior = noOverrideId ? NULL : get_behavior_from_id(overrideBehaviorId);
|
||||
|
@ -696,8 +671,7 @@ int smlua_hook_behavior(lua_State* L) {
|
|||
lua_pushvalue(L, 4);
|
||||
initReference = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
} else {
|
||||
LOG_LUA("Hook behavior: tried to reference non-function for init");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook behavior: tried to reference non-function for init");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -710,8 +684,7 @@ int smlua_hook_behavior(lua_State* L) {
|
|||
lua_pushvalue(L, 5);
|
||||
loopReference = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
} else {
|
||||
LOG_LUA("Hook behavior: tried to reference non-function for loop");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook behavior: tried to reference non-function for loop");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -772,8 +745,7 @@ bool smlua_call_behavior_hook(const BehaviorScript** behavior, struct Object* ob
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hooked->mod)) {
|
||||
LOG_LUA("Failed to call the behavior callback: %u, %s", hooked->behaviorId, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the behavior callback: %u", hooked->behaviorId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -805,34 +777,30 @@ int smlua_hook_chat_command(lua_State* L) {
|
|||
if (!smlua_functions_valid_param_count(L, 3)) { return 0; }
|
||||
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_chat_command() can only be called on load.");
|
||||
LOG_LUA_LINE("hook_chat_command() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sHookedChatCommandsCount >= MAX_HOOKED_CHAT_COMMANDS) {
|
||||
LOG_LUA("Hooked chat command exceeded maximum references!");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hooked chat command exceeded maximum references!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* command = smlua_to_string(L, 1);
|
||||
if (command == NULL || strlen(command) == 0 || !gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Hook chat command: tried to hook invalid command");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook chat command: tried to hook invalid command");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* description = smlua_to_string(L, 2);
|
||||
if (description == NULL || strlen(description) == 0 || !gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Hook chat command: tried to hook invalid description");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook chat command: tried to hook invalid description");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
if (ref == -1) {
|
||||
LOG_LUA("Hook chat command: tried to hook undefined function '%s'", command);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Hook chat command: tried to hook undefined function '%s'", command);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -875,8 +843,7 @@ bool smlua_call_chat_command_hook(char* command) {
|
|||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod)) {
|
||||
LOG_LUA("Failed to call the chat command callback: %s, %s", command, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
LOG_LUA("Failed to call the chat command callback: %s", command);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -922,19 +889,17 @@ int smlua_hook_on_sync_table_change(lua_State* L) {
|
|||
int funcIndex = 4;
|
||||
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_on_sync_table_change() can only be called on load.");
|
||||
LOG_LUA_LINE("hook_on_sync_table_change() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lua_type(L, syncTableIndex) != LUA_TTABLE) {
|
||||
LOG_LUA("Tried to attach a non-table to hook_on_sync_table_change: %d", lua_type(L, syncTableIndex));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Tried to attach a non-table to hook_on_sync_table_change: %d", lua_type(L, syncTableIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lua_type(L, funcIndex) != LUA_TFUNCTION) {
|
||||
LOG_LUA("Tried to attach a non-function to hook_on_sync_table_change: %d", lua_type(L, funcIndex));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Tried to attach a non-function to hook_on_sync_table_change: %d", lua_type(L, funcIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,7 @@ static bool smlua_sync_table_unwind(int syncTableIndex, int keyIndex) {
|
|||
// get key
|
||||
sUnwoundLnts[sUnwoundLntsCount++] = smlua_to_lnt(L, keyIndex);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("attempted to unwind sync table with invalid key type");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("attempted to unwind sync table with invalid key type");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -56,8 +55,7 @@ static bool smlua_sync_table_unwind(int syncTableIndex, int keyIndex) {
|
|||
while (true) {
|
||||
// make sure we remain within limits
|
||||
if (sUnwoundLntsCount >= MAX_UNWOUND_LNT) {
|
||||
LOG_LUA("attempted to unwind sync table past its limit");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("attempted to unwind sync table past its limit");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -78,9 +76,8 @@ static bool smlua_sync_table_unwind(int syncTableIndex, int keyIndex) {
|
|||
|
||||
lua_pop(L, 1); // pop _name value
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("attempted to unwind sync table with invalid parent");
|
||||
LOG_LUA_LINE("attempted to unwind sync table with invalid parent");
|
||||
lua_pop(L, 1); // pop iterative _parent
|
||||
smlua_logline();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -93,8 +90,7 @@ static bool smlua_sync_table_unwind(int syncTableIndex, int keyIndex) {
|
|||
// validate parent type
|
||||
if (parentType != LUA_TTABLE) {
|
||||
if (parentType != LUA_TNIL) {
|
||||
LOG_LUA("attempted to unwind sync table into an invalid parent");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("attempted to unwind sync table into an invalid parent");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
@ -110,8 +106,7 @@ static bool smlua_sync_table_unwind(int syncTableIndex, int keyIndex) {
|
|||
}
|
||||
|
||||
if (unwoundSize >= MAX_UNWOUND_SIZE) {
|
||||
LOG_LUA("attempted to unwind sync table with too long of a key/parent length");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("attempted to unwind sync table with too long of a key/parent length");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -147,9 +142,8 @@ static void smlua_sync_table_call_hook(int syncTableIndex, int keyIndex, int pre
|
|||
gLuaActiveMod = mod;
|
||||
gLuaLastHookMod = mod;
|
||||
gPcDebug.lastModRun = gLuaActiveMod;
|
||||
if (0 != lua_pcall(L, 3, 0, 0)) {
|
||||
LOG_LUA("Failed to call the hook_on_changed callback: %s", lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
if (0 != smlua_pcall(L, 3, 0, 0)) {
|
||||
LOG_LUA_LINE("Failed to call the hook_on_changed callback");
|
||||
}
|
||||
gLuaActiveMod = prev;
|
||||
}
|
||||
|
@ -171,16 +165,14 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al
|
|||
// get modRemoteIndex
|
||||
u16 modRemoteIndex = smlua_get_integer_field(syncTableIndex, "_remoteIndex");
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Error: tried to alter sync table with an invalid modRemoteIndex: %u", modRemoteIndex);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Error: tried to alter sync table with an invalid modRemoteIndex: %u", modRemoteIndex);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get key
|
||||
struct LSTNetworkType lntKey = smlua_to_lnt(L, keyIndex);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Error: tried to alter sync table with an invalid key");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Error: tried to alter sync table with an invalid key");
|
||||
return false;
|
||||
}
|
||||
lntKey = lntKey;
|
||||
|
@ -198,8 +190,7 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al
|
|||
int prevValueIndex = lua_gettop(L);
|
||||
|
||||
if (prevValueType == LUA_TTABLE) {
|
||||
LOG_LUA("Error: tried to assign on top of sync table");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Error: tried to assign on top of sync table");
|
||||
goto CLEANUP_STACK;
|
||||
}
|
||||
|
||||
|
@ -211,14 +202,12 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al
|
|||
int valueType = lua_type(L, valueIndex);
|
||||
if (valueType == LUA_TTABLE) {
|
||||
if (prevValueType != LUA_TNIL) {
|
||||
LOG_LUA("Error: tried to set a sync table field to a different sync table");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Error: tried to set a sync table field to a different sync table");
|
||||
goto CLEANUP_STACK;
|
||||
}
|
||||
|
||||
if (!smlua_is_table_empty(valueIndex)) {
|
||||
LOG_LUA("Error: tried to generate a sync table with a non-empty table");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Error: tried to generate a sync table with a non-empty table");
|
||||
goto CLEANUP_STACK;
|
||||
}
|
||||
|
||||
|
@ -237,8 +226,7 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al
|
|||
}
|
||||
struct LSTNetworkType lntValue = smlua_to_lnt(L, valueIndex);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Error: tried to alter sync table with an invalid value");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Error: tried to alter sync table with an invalid value");
|
||||
goto CLEANUP_STACK;
|
||||
}
|
||||
|
||||
|
@ -277,8 +265,7 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al
|
|||
|
||||
// unwind key + parent tables
|
||||
if (!smlua_sync_table_unwind(syncTableIndex, keyIndex)) {
|
||||
LOG_LUA("Error: failed to unwind sync table for sending over the network");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Error: failed to unwind sync table for sending over the network");
|
||||
goto CLEANUP_STACK;
|
||||
}
|
||||
|
||||
|
@ -432,17 +419,6 @@ void smlua_set_sync_table_field_from_network(u64 seq, u16 modRemoteIndex, u16 ln
|
|||
LUA_STACK_CHECK_END();
|
||||
}
|
||||
|
||||
static void smlua_exec_str(char* str) {
|
||||
LUA_STACK_CHECK_BEGIN();
|
||||
lua_State* L = gLuaState;
|
||||
if (luaL_dostring(L, str) != LUA_OK) {
|
||||
LOG_LUA("Failed to load lua string.");
|
||||
puts(smlua_to_string(L, lua_gettop(L)));
|
||||
smlua_logline();
|
||||
}
|
||||
LUA_STACK_CHECK_END();
|
||||
}
|
||||
|
||||
void smlua_sync_table_init_globals(char* path, u16 modRemoteIndex) {
|
||||
LUA_STACK_CHECK_BEGIN();
|
||||
lua_State* L = gLuaState;
|
||||
|
|
|
@ -28,7 +28,6 @@ void smlua_bind_function(lua_State* L, const char* name, void* func) {
|
|||
lua_setglobal(L, name);
|
||||
}
|
||||
|
||||
|
||||
bool smlua_is_table_empty(int index) {
|
||||
lua_pushnil(gLuaState); // key
|
||||
if (lua_next(gLuaState, index)) {
|
||||
|
@ -42,8 +41,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("smlua_to_boolean received improper type '%d'", lua_type(L, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_boolean received improper type '%d'", lua_type(L, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -55,8 +53,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("smlua_to_integer received improper type '%d'", lua_type(L, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_integer received improper type '%d'", lua_type(L, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -70,8 +67,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("smlua_to_number received improper type '%d'", lua_type(L, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_number received improper type '%d'", lua_type(L, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -81,8 +77,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("smlua_to_string received improper type '%d'", lua_type(L, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_string received improper type '%d'", lua_type(L, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -96,8 +91,7 @@ LuaFunction smlua_to_lua_function(lua_State* L, int index) {
|
|||
}
|
||||
|
||||
if (lua_type(L, index) != LUA_TFUNCTION) {
|
||||
LOG_LUA("smlua_to_lua_function received improper type '%d'", lua_type(L, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_lua_function received improper type '%d'", lua_type(L, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -108,9 +102,9 @@ LuaFunction smlua_to_lua_function(lua_State* L, int index) {
|
|||
}
|
||||
|
||||
void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
||||
if (lua_type(L, index) != LUA_TTABLE) {
|
||||
LOG_LUA("smlua_to_cobject received improper type '%d'", lua_type(L, index));
|
||||
smlua_logline();
|
||||
s32 indexType = lua_type(L, index);
|
||||
if (indexType != LUA_TTABLE) {
|
||||
LOG_LUA_LINE("smlua_to_cobject received improper type '%d'", lua_type(L, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -122,8 +116,7 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
|||
if (!gSmLuaConvertSuccess) { return NULL; }
|
||||
|
||||
if (lot != objLot) {
|
||||
LOG_LUA("smlua_to_cobject received improper LOT. Expected '%d', received '%d'", lot, objLot);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_cobject received improper LOT. Expected '%d', received '%d'", lot, objLot);
|
||||
gSmLuaConvertSuccess = false;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -136,14 +129,13 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
|||
|
||||
// check allowlist
|
||||
if (!smlua_cobject_allowlist_contains(lot, (u64)(intptr_t)pointer)) {
|
||||
LOG_LUA("smlua_to_cobject received a pointer not in allow list. '%u', '%llu", lot, (u64)(intptr_t)pointer);
|
||||
LOG_LUA_LINE("smlua_to_cobject received a pointer not in allow list. '%u', '%llu", lot, (u64)(intptr_t)pointer);
|
||||
gSmLuaConvertSuccess = false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pointer == NULL) {
|
||||
LOG_LUA("smlua_to_cobject received null pointer.");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_cobject received null pointer.");
|
||||
gSmLuaConvertSuccess = false;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -158,8 +150,7 @@ void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) {
|
|||
}
|
||||
|
||||
if (lua_type(L, index) != LUA_TTABLE) {
|
||||
LOG_LUA("smlua_to_cpointer received improper type '%d'", lua_type(L, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_cpointer received improper type '%d'", lua_type(L, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -171,8 +162,7 @@ void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) {
|
|||
if (!gSmLuaConvertSuccess) { return NULL; }
|
||||
|
||||
if (lvt != objLvt) {
|
||||
LOG_LUA("smlua_to_cpointer received improper LVT. Expected '%d', received '%d'", lvt, objLvt);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_cpointer received improper LVT. Expected '%d', received '%d'", lvt, objLvt);
|
||||
gSmLuaConvertSuccess = false;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -184,14 +174,13 @@ void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) {
|
|||
if (!gSmLuaConvertSuccess) { return NULL; }
|
||||
|
||||
if (!smlua_cpointer_allowlist_contains(lvt, (u64)(intptr_t)pointer)) {
|
||||
LOG_LUA("smlua_to_cpointer received a pointer not in allow list. '%u', '%llu", lvt, (u64)(intptr_t)pointer);
|
||||
LOG_LUA_LINE("smlua_to_cpointer received a pointer not in allow list. '%u', '%llu", lvt, (u64)(intptr_t)pointer);
|
||||
gSmLuaConvertSuccess = false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pointer == NULL) {
|
||||
LOG_LUA("smlua_to_cpointer received null pointer.");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_cpointer received null pointer.");
|
||||
gSmLuaConvertSuccess = false;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -235,8 +224,7 @@ struct LSTNetworkType smlua_to_lnt(lua_State* L, int index) {
|
|||
lnt.type = LST_NETWORK_TYPE_STRING;
|
||||
lnt.value.string = (char*)lua_tostring(L, index);
|
||||
if (lnt.value.string == NULL || strlen(lnt.value.string) > 256) {
|
||||
LOG_LUA("smlua_to_lnt on invalid string value: '%s'", (lnt.value.string == NULL) ? "<null>" : lnt.value.string);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_lnt on invalid string value: '%s'", (lnt.value.string == NULL) ? "<null>" : lnt.value.string);
|
||||
gSmLuaConvertSuccess = false;
|
||||
return lnt;
|
||||
}
|
||||
|
@ -252,8 +240,7 @@ struct LSTNetworkType smlua_to_lnt(lua_State* L, int index) {
|
|||
return lnt;
|
||||
}
|
||||
|
||||
LOG_LUA("smlua_to_lnt on invalid type: '%d'", valueType);
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_to_lnt on invalid type: '%d'", valueType);
|
||||
gSmLuaConvertSuccess = false;
|
||||
return lnt;
|
||||
}
|
||||
|
@ -437,8 +424,7 @@ void smlua_push_lnt(struct LSTNetworkType* lnt) {
|
|||
|
||||
lua_Integer smlua_get_integer_field(int index, char* name) {
|
||||
if (lua_type(gLuaState, index) != LUA_TTABLE) {
|
||||
LOG_LUA("smlua_get_integer_field received improper type '%d'", lua_type(gLuaState, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_get_integer_field received improper type '%d'", lua_type(gLuaState, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
@ -450,8 +436,7 @@ lua_Integer smlua_get_integer_field(int index, char* name) {
|
|||
|
||||
lua_Number smlua_get_number_field(int index, char* name) {
|
||||
if (lua_type(gLuaState, index) != LUA_TTABLE) {
|
||||
LOG_LUA("smlua_get_number_field received improper type '%d'", lua_type(gLuaState, index));
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("smlua_get_number_field received improper type '%d'", lua_type(gLuaState, index));
|
||||
gSmLuaConvertSuccess = false;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -89,18 +89,18 @@ bool smlua_audio_utils_override(u8 sequenceId, s32* bankId, void** seqData) {
|
|||
void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolume, const char* m64Name) {
|
||||
if (gLuaActiveMod == NULL) { return; }
|
||||
if (sequenceId >= MAX_OVERRIDE) {
|
||||
LOG_LUA("Invalid sequenceId given to smlua_audio_utils_replace_sequence(): %d", sequenceId);
|
||||
LOG_LUA_LINE("Invalid sequenceId given to smlua_audio_utils_replace_sequence(): %d", sequenceId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bankId >= 64) {
|
||||
LOG_LUA("Invalid bankId given to smlua_audio_utils_replace_sequence(): %d", bankId);
|
||||
LOG_LUA_LINE("Invalid bankId given to smlua_audio_utils_replace_sequence(): %d", bankId);
|
||||
return;
|
||||
}
|
||||
|
||||
char m64path[SYS_MAX_PATH] = { 0 };
|
||||
if (snprintf(m64path, SYS_MAX_PATH-1, "sound/%s.m64", m64Name) < 0) {
|
||||
LOG_LUA("Could not concat m64path: %s", m64path);
|
||||
LOG_LUA_LINE("Could not concat m64path: %s", m64path);
|
||||
return;
|
||||
}
|
||||
normalize_path(m64path);
|
||||
|
@ -122,5 +122,5 @@ void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolu
|
|||
}
|
||||
}
|
||||
|
||||
LOG_LUA("Could not find m64 at path: %s", m64path);
|
||||
LOG_LUA_LINE("Could not find m64 at path: %s", m64path);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ s32* get_temp_s32_pointer(s32 initialValue) {
|
|||
|
||||
s32 deref_s32_pointer(s32* pointer) {
|
||||
if (pointer == NULL) {
|
||||
LOG_LUA("Tried to dereference null pointer!");
|
||||
LOG_LUA_LINE("Tried to dereference null pointer!");
|
||||
return 0;
|
||||
}
|
||||
return *pointer;
|
||||
|
|
|
@ -58,9 +58,8 @@ static struct Object* spawn_object_internal(enum BehaviorId behaviorId, enum Mod
|
|||
lua_State* L = gLuaState;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, objSetupFunction);
|
||||
smlua_push_object(L, LOT_OBJECT, obj);
|
||||
if (0 != lua_pcall(L, 1, 0, 0)) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", objSetupFunction, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
if (0 != smlua_pcall(L, 1, 0, 0)) {
|
||||
LOG_LUA("Failed to call the object setup callback: %u", objSetupFunction);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ void network_send_lua_custom(bool broadcast) {
|
|||
|
||||
// figure out mod index
|
||||
if (gLuaActiveMod == NULL) {
|
||||
LOG_LUA("Could not figure out the current active mod!");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Could not figure out the current active mod!");
|
||||
return;
|
||||
}
|
||||
u16 modIndex = gLuaActiveMod->index;
|
||||
|
@ -24,8 +23,7 @@ void network_send_lua_custom(bool broadcast) {
|
|||
if (!broadcast) {
|
||||
s32 toLocalIndex = smlua_to_integer(L, paramIndex++);
|
||||
if (toLocalIndex <= 0 || toLocalIndex >= MAX_PLAYERS) {
|
||||
LOG_LUA("Tried to send packet to invalid local index: %d", toLocalIndex)
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Tried to send packet to invalid local index: %d", toLocalIndex)
|
||||
return;
|
||||
}
|
||||
if (!gSmLuaConvertSuccess) { return; }
|
||||
|
@ -45,8 +43,7 @@ void network_send_lua_custom(bool broadcast) {
|
|||
// make sure value passed in is a table
|
||||
s32 tableIndex = paramIndex;
|
||||
if (lua_type(L, tableIndex) != LUA_TTABLE) {
|
||||
LOG_LUA("Tried to send a packet with a non-table");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Tried to send a packet with a non-table");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,8 +54,7 @@ void network_send_lua_custom(bool broadcast) {
|
|||
// convert and write key
|
||||
struct LSTNetworkType lntKey = smlua_to_lnt(L, -2);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Failed to convert key to LNT (tx)");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Failed to convert key to LNT (tx)");
|
||||
return;
|
||||
}
|
||||
if (!packet_write_lnt(&p, &lntKey)) {
|
||||
|
@ -68,8 +64,7 @@ void network_send_lua_custom(bool broadcast) {
|
|||
// convert and write value
|
||||
struct LSTNetworkType lntValue = smlua_to_lnt(L, -1);
|
||||
if (!gSmLuaConvertSuccess) {
|
||||
LOG_LUA("Failed to convert value to LNT (tx)");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Failed to convert value to LNT (tx)");
|
||||
return;
|
||||
}
|
||||
if (!packet_write_lnt(&p, &lntValue)) {
|
||||
|
@ -103,16 +98,14 @@ void network_receive_lua_custom(struct Packet* p) {
|
|||
for(u16 i = 0; i < keyCount; i++) {
|
||||
struct LSTNetworkType lntKey = { 0 };
|
||||
if (!packet_read_lnt(p, &lntKey)) {
|
||||
LOG_LUA("Failed to convert key to LNT (rx)");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Failed to convert key to LNT (rx)");
|
||||
return;
|
||||
}
|
||||
smlua_push_lnt(&lntKey);
|
||||
|
||||
struct LSTNetworkType lntValue = { 0 };
|
||||
if (!packet_read_lnt(p, &lntValue)) {
|
||||
LOG_LUA("Failed to convert value to LNT (rx)");
|
||||
smlua_logline();
|
||||
LOG_LUA_LINE("Failed to convert value to LNT (rx)");
|
||||
return;
|
||||
}
|
||||
smlua_push_lnt(&lntValue);
|
||||
|
|
Loading…
Reference in a new issue