mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-12-19 14:32:28 +00:00
fix some issues with smlua
get_temp_s32_pointer and deref_s32_pointer: these are actually safe and mods use them fixed a nil script error with smlua_to_cpointer
This commit is contained in:
parent
c27b9c0e87
commit
ecac2afd07
8 changed files with 124 additions and 6 deletions
|
|
@ -10247,6 +10247,20 @@ function get_area_update_counter()
|
||||||
-- ...
|
-- ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param initialValue integer
|
||||||
|
--- @return Pointer_integer
|
||||||
|
--- Returns a temporary signed 32-bit integer pointer with its value set to `initialValue`
|
||||||
|
function get_temp_s32_pointer(initialValue)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @param pointer Pointer_integer
|
||||||
|
--- @return integer
|
||||||
|
--- Gets the signed 32-bit integer value from `pointer`
|
||||||
|
function deref_s32_pointer(pointer)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
--- @param message string
|
--- @param message string
|
||||||
--- @param lines integer
|
--- @param lines integer
|
||||||
--- Creates a DJUI popup that is broadcasted to every client
|
--- Creates a DJUI popup that is broadcasted to every client
|
||||||
|
|
|
||||||
|
|
@ -2936,6 +2936,52 @@ Gets the area update counter incremented when objects are updated
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [get_temp_s32_pointer](#get_temp_s32_pointer)
|
||||||
|
|
||||||
|
### Description
|
||||||
|
Returns a temporary signed 32-bit integer pointer with its value set to `initialValue`
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local PointerValue = get_temp_s32_pointer(initialValue)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| initialValue | `integer` |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- `Pointer` <`integer`>
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`s32* get_temp_s32_pointer(s32 initialValue);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
## [deref_s32_pointer](#deref_s32_pointer)
|
||||||
|
|
||||||
|
### Description
|
||||||
|
Gets the signed 32-bit integer value from `pointer`
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local integerValue = deref_s32_pointer(pointer)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| pointer | `Pointer` <`integer`> |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- `integer`
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`s32 deref_s32_pointer(s32* pointer);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
## [djui_popup_create_global](#djui_popup_create_global)
|
## [djui_popup_create_global](#djui_popup_create_global)
|
||||||
|
|
||||||
### Description
|
### Description
|
||||||
|
|
|
||||||
|
|
@ -1861,6 +1861,8 @@
|
||||||
- smlua_misc_utils.h
|
- smlua_misc_utils.h
|
||||||
- [get_network_area_timer](functions-6.md#get_network_area_timer)
|
- [get_network_area_timer](functions-6.md#get_network_area_timer)
|
||||||
- [get_area_update_counter](functions-6.md#get_area_update_counter)
|
- [get_area_update_counter](functions-6.md#get_area_update_counter)
|
||||||
|
- [get_temp_s32_pointer](functions-6.md#get_temp_s32_pointer)
|
||||||
|
- [deref_s32_pointer](functions-6.md#deref_s32_pointer)
|
||||||
- [djui_popup_create_global](functions-6.md#djui_popup_create_global)
|
- [djui_popup_create_global](functions-6.md#djui_popup_create_global)
|
||||||
- [djui_is_popup_disabled](functions-6.md#djui_is_popup_disabled)
|
- [djui_is_popup_disabled](functions-6.md#djui_is_popup_disabled)
|
||||||
- [djui_set_popup_disabled_override](functions-6.md#djui_set_popup_disabled_override)
|
- [djui_set_popup_disabled_override](functions-6.md#djui_set_popup_disabled_override)
|
||||||
|
|
|
||||||
|
|
@ -1081,7 +1081,7 @@ int smlua_func_gfx_set_command(lua_State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx* gfx = smlua_to_cobject(L, 1, LOT_GFX);
|
Gfx* gfx = smlua_to_cobject(L, 1, LOT_GFX);
|
||||||
if (!gSmLuaConvertSuccess) {
|
if (!gSmLuaConvertSuccess || !gfx) {
|
||||||
LOG_LUA("gfx_set_command: Failed to convert parameter %u", 1);
|
LOG_LUA("gfx_set_command: Failed to convert parameter %u", 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30875,6 +30875,40 @@ int smlua_func_get_area_update_counter(UNUSED lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smlua_func_get_temp_s32_pointer(lua_State* L) {
|
||||||
|
if (L == NULL) { return 0; }
|
||||||
|
|
||||||
|
int top = lua_gettop(L);
|
||||||
|
if (top != 1) {
|
||||||
|
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_temp_s32_pointer", 1, top);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
s32 initialValue = smlua_to_integer(L, 1);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_temp_s32_pointer"); return 0; }
|
||||||
|
|
||||||
|
smlua_push_pointer(L, LVT_S32_P, (void*)get_temp_s32_pointer(initialValue), NULL);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int smlua_func_deref_s32_pointer(lua_State* L) {
|
||||||
|
if (L == NULL) { return 0; }
|
||||||
|
|
||||||
|
int top = lua_gettop(L);
|
||||||
|
if (top != 1) {
|
||||||
|
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "deref_s32_pointer", 1, top);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
s32* pointer = (s32*)smlua_to_cpointer(L, 1, LVT_S32_P);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "deref_s32_pointer"); return 0; }
|
||||||
|
|
||||||
|
lua_pushinteger(L, deref_s32_pointer(pointer));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int smlua_func_djui_popup_create_global(lua_State* L) {
|
int smlua_func_djui_popup_create_global(lua_State* L) {
|
||||||
if (L == NULL) { return 0; }
|
if (L == NULL) { return 0; }
|
||||||
|
|
||||||
|
|
@ -35793,6 +35827,8 @@ void smlua_bind_functions_autogen(void) {
|
||||||
// smlua_misc_utils.h
|
// smlua_misc_utils.h
|
||||||
smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer);
|
smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer);
|
||||||
smlua_bind_function(L, "get_area_update_counter", smlua_func_get_area_update_counter);
|
smlua_bind_function(L, "get_area_update_counter", smlua_func_get_area_update_counter);
|
||||||
|
smlua_bind_function(L, "get_temp_s32_pointer", smlua_func_get_temp_s32_pointer);
|
||||||
|
smlua_bind_function(L, "deref_s32_pointer", smlua_func_deref_s32_pointer);
|
||||||
smlua_bind_function(L, "djui_popup_create_global", smlua_func_djui_popup_create_global);
|
smlua_bind_function(L, "djui_popup_create_global", smlua_func_djui_popup_create_global);
|
||||||
smlua_bind_function(L, "djui_is_popup_disabled", smlua_func_djui_is_popup_disabled);
|
smlua_bind_function(L, "djui_is_popup_disabled", smlua_func_djui_is_popup_disabled);
|
||||||
smlua_bind_function(L, "djui_set_popup_disabled_override", smlua_func_djui_set_popup_disabled_override);
|
smlua_bind_function(L, "djui_set_popup_disabled_override", smlua_func_djui_set_popup_disabled_override);
|
||||||
|
|
|
||||||
|
|
@ -150,12 +150,10 @@ bool smlua_is_cobject(lua_State* L, int index, UNUSED u16 lot) {
|
||||||
|
|
||||||
void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
||||||
s32 indexType = lua_type(L, index);
|
s32 indexType = lua_type(L, index);
|
||||||
|
if (indexType == LUA_TNIL) { return NULL; }
|
||||||
if (indexType != LUA_TUSERDATA) {
|
if (indexType != LUA_TUSERDATA) {
|
||||||
// suppress script errors
|
|
||||||
if (indexType != LUA_TNIL) {
|
|
||||||
LOG_LUA_LINE("smlua_to_cobject received improper type '%s'", lua_typename(L, indexType));
|
LOG_LUA_LINE("smlua_to_cobject received improper type '%s'", lua_typename(L, indexType));
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,6 +177,7 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
|
||||||
|
|
||||||
void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) {
|
void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) {
|
||||||
s32 indexType = lua_type(L, index);
|
s32 indexType = lua_type(L, index);
|
||||||
|
if (indexType == LUA_TNIL) { return NULL; }
|
||||||
if (indexType != LUA_TUSERDATA) {
|
if (indexType != LUA_TUSERDATA) {
|
||||||
LOG_LUA_LINE("smlua_to_cpointer received improper type '%s'", lua_typename(L, indexType));
|
LOG_LUA_LINE("smlua_to_cpointer received improper type '%s'", lua_typename(L, indexType));
|
||||||
gSmLuaConvertSuccess = false;
|
gSmLuaConvertSuccess = false;
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,22 @@ u16 get_area_update_counter(void) {
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
||||||
|
s32* get_temp_s32_pointer(s32 initialValue) {
|
||||||
|
static s32 value = 0;
|
||||||
|
value = initialValue;
|
||||||
|
return &value;
|
||||||
|
}
|
||||||
|
|
||||||
|
s32 deref_s32_pointer(s32* pointer) {
|
||||||
|
if (pointer == NULL) {
|
||||||
|
LOG_LUA_LINE("Tried to dereference null pointer!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return *pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
|
||||||
void djui_popup_create_global(const char* message, int lines) {
|
void djui_popup_create_global(const char* message, int lines) {
|
||||||
djui_popup_create(message, lines);
|
djui_popup_create(message, lines);
|
||||||
network_send_global_popup(message, lines);
|
network_send_global_popup(message, lines);
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,11 @@ u32 get_network_area_timer(void);
|
||||||
/* |description|Gets the area update counter incremented when objects are updated|descriptionEnd| */
|
/* |description|Gets the area update counter incremented when objects are updated|descriptionEnd| */
|
||||||
u16 get_area_update_counter(void);
|
u16 get_area_update_counter(void);
|
||||||
|
|
||||||
|
/* |description|Returns a temporary signed 32-bit integer pointer with its value set to `initialValue`|descriptionEnd| */
|
||||||
|
s32* get_temp_s32_pointer(s32 initialValue);
|
||||||
|
/* |description|Gets the signed 32-bit integer value from `pointer`|descriptionEnd| */
|
||||||
|
s32 deref_s32_pointer(s32* pointer);
|
||||||
|
|
||||||
/* |description|Creates a DJUI popup that is broadcasted to every client|descriptionEnd| */
|
/* |description|Creates a DJUI popup that is broadcasted to every client|descriptionEnd| */
|
||||||
void djui_popup_create_global(const char* message, int lines);
|
void djui_popup_create_global(const char* message, int lines);
|
||||||
/* |description|Returns if popups are disabled|descriptionEnd| */
|
/* |description|Returns if popups are disabled|descriptionEnd| */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue