mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Made Lua log to console outside of DEBUG builds
This commit is contained in:
parent
6b67d3b6a7
commit
3d5d0b5306
6 changed files with 49 additions and 23 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
function mario_before_phys_step(m)
|
function mario_before_phys_step(m)
|
||||||
local hScale = 1.0
|
local hScale = 1.0
|
||||||
|
local vScale = 1.0
|
||||||
|
|
||||||
-- faster swimming
|
-- faster swimming
|
||||||
if (m.action & ACT_FLAG_SWIMMING) ~= 0 then
|
if (m.action & ACT_FLAG_SWIMMING) ~= 0 then
|
||||||
|
|
@ -14,6 +15,7 @@ function mario_before_phys_step(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
m.vel.x = m.vel.x * hScale
|
m.vel.x = m.vel.x * hScale
|
||||||
|
m.vel.y = m.vel.y * vScale
|
||||||
m.vel.z = m.vel.z * hScale
|
m.vel.z = m.vel.z * hScale
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ lua_State* gLuaState = NULL;
|
||||||
static void smlua_exec_file(char* path) {
|
static void smlua_exec_file(char* path) {
|
||||||
lua_State* L = gLuaState;
|
lua_State* L = gLuaState;
|
||||||
if (luaL_dofile(L, path) != LUA_OK) {
|
if (luaL_dofile(L, path) != LUA_OK) {
|
||||||
LOG_LUA("LUA: Failed to load lua file '%s'.", path);
|
LOG_LUA("Failed to load lua file '%s'.", path);
|
||||||
puts(smlua_to_string(L, lua_gettop(L)));
|
puts(smlua_to_string(L, lua_gettop(L)));
|
||||||
}
|
}
|
||||||
lua_pop(L, lua_gettop(L));
|
lua_pop(L, lua_gettop(L));
|
||||||
|
|
@ -15,7 +15,7 @@ static void smlua_exec_file(char* path) {
|
||||||
static void smlua_exec_str(char* str) {
|
static void smlua_exec_str(char* str) {
|
||||||
lua_State* L = gLuaState;
|
lua_State* L = gLuaState;
|
||||||
if (luaL_dostring(L, str) != LUA_OK) {
|
if (luaL_dostring(L, str) != LUA_OK) {
|
||||||
LOG_LUA("LUA: Failed to load lua string.");
|
LOG_LUA("Failed to load lua string.");
|
||||||
puts(smlua_to_string(L, lua_gettop(L)));
|
puts(smlua_to_string(L, lua_gettop(L)));
|
||||||
}
|
}
|
||||||
lua_pop(L, lua_gettop(L));
|
lua_pop(L, lua_gettop(L));
|
||||||
|
|
@ -24,7 +24,7 @@ static void smlua_exec_str(char* str) {
|
||||||
static void smlua_load_script(char* path) {
|
static void smlua_load_script(char* path) {
|
||||||
lua_State* L = gLuaState;
|
lua_State* L = gLuaState;
|
||||||
if (luaL_loadfile(L, path) != LUA_OK) {
|
if (luaL_loadfile(L, path) != LUA_OK) {
|
||||||
LOG_LUA("LUA: Failed to load lua script '%s'.", path);
|
LOG_LUA("Failed to load lua script '%s'.", path);
|
||||||
puts(smlua_to_string(L, lua_gettop(L)));
|
puts(smlua_to_string(L, lua_gettop(L)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +44,7 @@ static void smlua_load_script(char* path) {
|
||||||
|
|
||||||
// run chunks
|
// run chunks
|
||||||
if (lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) {
|
if (lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) {
|
||||||
LOG_LUA("LUA: Failed to execute lua script '%s'.", path);
|
LOG_LUA("Failed to execute lua script '%s'.", path);
|
||||||
puts(smlua_to_string(L, lua_gettop(L)));
|
puts(smlua_to_string(L, lua_gettop(L)));
|
||||||
smlua_dump_stack();
|
smlua_dump_stack();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "pc/debuglog.h"
|
#include "pc/debuglog.h"
|
||||||
|
|
||||||
#define LOG_LUA LOG_INFO
|
#define LOG_LUA(...) ( _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n") )
|
||||||
|
|
||||||
extern lua_State* gLuaState;
|
extern lua_State* gLuaState;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,25 @@ int smlua_hook_event(lua_State* L) {
|
||||||
if (!gSmLuaConvertSuccess) { return 0; }
|
if (!gSmLuaConvertSuccess) { return 0; }
|
||||||
|
|
||||||
if (hookType >= HOOK_MAX) {
|
if (hookType >= HOOK_MAX) {
|
||||||
LOG_LUA("LUA: Hook Type: %d exceeds max!", hookType);
|
LOG_LUA("Hook Type: %d exceeds max!", hookType);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
|
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
|
||||||
if (hook->count >= MAX_HOOKED_REFERENCES) {
|
if (hook->count >= MAX_HOOKED_REFERENCES) {
|
||||||
LOG_LUA("LUA: Hook Type: %d exceeded maximum references!", hookType);
|
LOG_LUA("Hook Type: %s exceeded maximum references!", LuaHookedEventTypeName[hookType]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hook->reference[hook->count] = luaL_ref(L, LUA_REGISTRYINDEX);
|
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
if (ref == -1) {
|
||||||
|
LOG_LUA("tried to hook undefined function to '%s'", LuaHookedEventTypeName[hookType]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hook->reference[hook->count] = ref;
|
||||||
hook->count++;
|
hook->count++;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +47,7 @@ void smlua_call_event_hooks(enum LuaHookedEventType hookType) {
|
||||||
|
|
||||||
// call the callback
|
// call the callback
|
||||||
if (0 != lua_pcall(L, 0, 0, 0)) {
|
if (0 != lua_pcall(L, 0, 0, 0)) {
|
||||||
LOG_LUA("LUA: Failed to call the callback: %s", lua_tostring(L, -1));
|
LOG_LUA("Failed to call the callback: %s", lua_tostring(L, -1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +69,7 @@ void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct
|
||||||
|
|
||||||
// call the callback
|
// call the callback
|
||||||
if (0 != lua_pcall(L, 1, 0, 0)) {
|
if (0 != lua_pcall(L, 1, 0, 0)) {
|
||||||
LOG_LUA("LUA: Failed to call the callback: %s", lua_tostring(L, -1));
|
LOG_LUA("Failed to call the callback: %s", lua_tostring(L, -1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,13 +92,21 @@ static int sHookedMarioActionsCount = 0;
|
||||||
int smlua_hook_mario_action(lua_State* L) {
|
int smlua_hook_mario_action(lua_State* L) {
|
||||||
if (L == NULL) { return 0; }
|
if (L == NULL) { return 0; }
|
||||||
if (sHookedMarioActionsCount >= MAX_HOOKED_ACTIONS) {
|
if (sHookedMarioActionsCount >= MAX_HOOKED_ACTIONS) {
|
||||||
LOG_LUA("LUA: Hooked mario actions exceeded maximum references!");
|
LOG_LUA("Hooked mario actions exceeded maximum references!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_Integer action = smlua_to_integer(L, -2);
|
||||||
|
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
|
if (ref == -1) {
|
||||||
|
LOG_LUA("Hook Action: %lld tried to hook undefined function", action);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LuaHookedMarioAction* hooked = &sHookedMarioActions[sHookedMarioActionsCount];
|
struct LuaHookedMarioAction* hooked = &sHookedMarioActions[sHookedMarioActionsCount];
|
||||||
hooked->action = smlua_to_integer(L, -2);
|
hooked->action = action;
|
||||||
hooked->reference = luaL_ref(L, LUA_REGISTRYINDEX);
|
hooked->reference = ref;
|
||||||
if (!gSmLuaConvertSuccess) { return 0; }
|
if (!gSmLuaConvertSuccess) { return 0; }
|
||||||
|
|
||||||
sHookedMarioActionsCount++;
|
sHookedMarioActionsCount++;
|
||||||
|
|
@ -114,7 +129,7 @@ bool smlua_call_action_hook(struct MarioState* m, s32* returnValue) {
|
||||||
|
|
||||||
// call the callback
|
// call the callback
|
||||||
if (0 != lua_pcall(L, 1, 1, 0)) {
|
if (0 != lua_pcall(L, 1, 1, 0)) {
|
||||||
LOG_LUA("LUA: Failed to call the callback: %s", lua_tostring(L, -1));
|
LOG_LUA("Failed to call the callback: %s", lua_tostring(L, -1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,15 @@ enum LuaHookedEventType {
|
||||||
HOOK_MAX,
|
HOOK_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char* LuaHookedEventTypeName[] = {
|
||||||
|
"HOOK_UPDATE",
|
||||||
|
"HOOK_MARIO_UPDATE",
|
||||||
|
"HOOK_BEFORE_MARIO_UPDATE",
|
||||||
|
"HOOK_ON_SET_MARIO_ACTION",
|
||||||
|
"HOOK_BEFORE_PHYS_STEP",
|
||||||
|
"HOOK_MAX"
|
||||||
|
};
|
||||||
|
|
||||||
void smlua_call_event_hooks(enum LuaHookedEventType hookType);
|
void smlua_call_event_hooks(enum LuaHookedEventType hookType);
|
||||||
void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m);
|
void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m);
|
||||||
bool smlua_call_action_hook(struct MarioState* m, s32* returnValue);
|
bool smlua_call_action_hook(struct MarioState* m, s32* returnValue);
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ lua_Integer smlua_to_integer(lua_State* L, int index) {
|
||||||
if (lua_type(L, index) == LUA_TBOOLEAN) {
|
if (lua_type(L, index) == LUA_TBOOLEAN) {
|
||||||
return lua_toboolean(L, index) ? 1 : 0;
|
return lua_toboolean(L, index) ? 1 : 0;
|
||||||
} else if (lua_type(L, index) != LUA_TNUMBER) {
|
} else if (lua_type(L, index) != LUA_TNUMBER) {
|
||||||
LOG_LUA("LUA: smlua_to_integer received improper type '%d'", lua_type(L, index));
|
LOG_LUA("smlua_to_integer received improper type '%d'", lua_type(L, index));
|
||||||
smlua_logline();
|
smlua_logline();
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -56,7 +56,7 @@ lua_Integer smlua_to_integer(lua_State* L, int index) {
|
||||||
|
|
||||||
lua_Number smlua_to_number(lua_State* L, int index) {
|
lua_Number smlua_to_number(lua_State* L, int index) {
|
||||||
if (lua_type(L, index) != LUA_TNUMBER) {
|
if (lua_type(L, index) != LUA_TNUMBER) {
|
||||||
LOG_LUA("LUA: smlua_to_number received improper type '%d'", lua_type(L, index));
|
LOG_LUA("smlua_to_number received improper type '%d'", lua_type(L, index));
|
||||||
smlua_logline();
|
smlua_logline();
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -67,7 +67,7 @@ lua_Number smlua_to_number(lua_State* L, int index) {
|
||||||
|
|
||||||
const char* smlua_to_string(lua_State* L, int index) {
|
const char* smlua_to_string(lua_State* L, int index) {
|
||||||
if (lua_type(L, index) != LUA_TSTRING) {
|
if (lua_type(L, index) != LUA_TSTRING) {
|
||||||
LOG_LUA("LUA: smlua_to_string received improper type '%d'", lua_type(L, index));
|
LOG_LUA("smlua_to_string received improper type '%d'", lua_type(L, index));
|
||||||
smlua_logline();
|
smlua_logline();
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -78,7 +78,7 @@ const char* smlua_to_string(lua_State* L, int index) {
|
||||||
|
|
||||||
void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
||||||
if (lua_type(L, index) != LUA_TTABLE) {
|
if (lua_type(L, index) != LUA_TTABLE) {
|
||||||
LOG_LUA("LUA: smlua_to_cobject received improper type '%d'", lua_type(L, index));
|
LOG_LUA("smlua_to_cobject received improper type '%d'", lua_type(L, index));
|
||||||
smlua_logline();
|
smlua_logline();
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -91,7 +91,7 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
||||||
if (!gSmLuaConvertSuccess) { return NULL; }
|
if (!gSmLuaConvertSuccess) { return NULL; }
|
||||||
|
|
||||||
if (lot != objLot) {
|
if (lot != objLot) {
|
||||||
LOG_LUA("LUA: smlua_to_cobject received improper LOT. Expected '%d', received '%d'", lot, objLot);
|
LOG_LUA("smlua_to_cobject received improper LOT. Expected '%d', received '%d'", lot, objLot);
|
||||||
smlua_logline();
|
smlua_logline();
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -105,13 +105,13 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
||||||
|
|
||||||
// check allowlist
|
// check allowlist
|
||||||
if (!smlua_cobject_allowlist_contains(lot, (u64)pointer)) {
|
if (!smlua_cobject_allowlist_contains(lot, (u64)pointer)) {
|
||||||
LOG_LUA("LUA: smlua_to_cobject received a pointer not in allow list. '%u', '%llu", lot, (u64)pointer);
|
LOG_LUA("smlua_to_cobject received a pointer not in allow list. '%u', '%llu", lot, (u64)pointer);
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pointer == NULL) {
|
if (pointer == NULL) {
|
||||||
LOG_LUA("LUA: smlua_to_cobject received null pointer.");
|
LOG_LUA("smlua_to_cobject received null pointer.");
|
||||||
smlua_logline();
|
smlua_logline();
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -153,7 +153,7 @@ void smlua_push_number_field(int index, char* name, lua_Number val) {
|
||||||
|
|
||||||
lua_Integer smlua_get_integer_field(int index, char* name) {
|
lua_Integer smlua_get_integer_field(int index, char* name) {
|
||||||
if (lua_type(gLuaState, index) != LUA_TTABLE) {
|
if (lua_type(gLuaState, index) != LUA_TTABLE) {
|
||||||
LOG_LUA("LUA: smlua_get_integer_field received improper type '%d'", lua_type(gLuaState, index));
|
LOG_LUA("smlua_get_integer_field received improper type '%d'", lua_type(gLuaState, index));
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +165,7 @@ lua_Integer smlua_get_integer_field(int index, char* name) {
|
||||||
|
|
||||||
lua_Number smlua_get_number_field(int index, char* name) {
|
lua_Number smlua_get_number_field(int index, char* name) {
|
||||||
if (lua_type(gLuaState, index) != LUA_TTABLE) {
|
if (lua_type(gLuaState, index) != LUA_TTABLE) {
|
||||||
LOG_LUA("LUA: smlua_get_number_field received improper type '%d'", lua_type(gLuaState, index));
|
LOG_LUA("smlua_get_number_field received improper type '%d'", lua_type(gLuaState, index));
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue