mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-25 13:35:12 +00:00
Added Lua function param count checking
This commit is contained in:
parent
b45c61a605
commit
7d3769a216
6 changed files with 458 additions and 2 deletions
|
@ -202,6 +202,8 @@ def build_function(function):
|
|||
else:
|
||||
s = 'int smlua_func_%s(lua_State* L) {\n' % function['identifier']
|
||||
|
||||
s += ' if(!smlua_functions_valid_param_count(L, %d)) { return 0; }\n\n' % len(function['params'])
|
||||
|
||||
i = 1
|
||||
for param in function['params']:
|
||||
s += build_param(param, i)
|
||||
|
|
|
@ -9,11 +9,23 @@
|
|||
#include "object_fields.h"
|
||||
#include "engine/math_util.h"
|
||||
|
||||
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();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////
|
||||
// misc //
|
||||
//////////
|
||||
|
||||
int smlua_func_sins(lua_State* L) {
|
||||
if (!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
f32 x = smlua_to_number(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
|
@ -22,6 +34,8 @@ int smlua_func_sins(lua_State* L) {
|
|||
}
|
||||
|
||||
int smlua_func_coss(lua_State* L) {
|
||||
if (!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
f32 x = smlua_to_number(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
|
@ -30,6 +44,8 @@ int smlua_func_coss(lua_State* L) {
|
|||
}
|
||||
|
||||
int smlua_func_atan2s(lua_State* L) {
|
||||
if (!smlua_functions_valid_param_count(L, 2)) { return 0; }
|
||||
|
||||
f32 y = smlua_to_number(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
f32 x = smlua_to_number(L, 2);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SMLUA_FUNCTIONS_H
|
||||
#define SMLUA_FUNCTIONS_H
|
||||
|
||||
bool smlua_functions_valid_param_count(lua_State* L, int expected);
|
||||
void smlua_bind_functions(void);
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -25,13 +25,13 @@ void smlua_bind_function(lua_State* L, const char* name, void* func) {
|
|||
lua_setglobal(L, name);
|
||||
}
|
||||
|
||||
static void smlua_logline(void) {
|
||||
void smlua_logline(void) {
|
||||
lua_State* L = gLuaState;
|
||||
lua_Debug info;
|
||||
int level = 0;
|
||||
while (lua_getstack(L, level, &info)) {
|
||||
lua_getinfo(L, "nSl", &info);
|
||||
LOG_INFO(" [%d] %s:%d -- %s [%s]\n",
|
||||
LOG_INFO(" [%d] %s:%d -- %s [%s]",
|
||||
level, info.short_src, info.currentline,
|
||||
(info.name ? info.name : "<unknown>"), info.what);
|
||||
++level;
|
||||
|
|
|
@ -7,6 +7,7 @@ f32* smlua_get_vec3f_from_buffer(void);
|
|||
s16* smlua_get_vec3s_from_buffer(void);
|
||||
|
||||
void smlua_bind_function(lua_State* L, const char* name, void* func);
|
||||
void smlua_logline(void);
|
||||
|
||||
lua_Integer smlua_to_integer(lua_State* L, int index);
|
||||
lua_Number smlua_to_number(lua_State* L, int index);
|
||||
|
|
Loading…
Reference in a new issue