mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Add mod_storage_exists
This commit is contained in:
parent
bff0cda663
commit
856a828229
6 changed files with 62 additions and 0 deletions
|
|
@ -5389,6 +5389,12 @@ function mod_storage_clear()
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @param key string
|
||||
--- @return boolean
|
||||
function mod_storage_exists(key)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param key string
|
||||
--- @return string
|
||||
function mod_storage_load(key)
|
||||
|
|
|
|||
|
|
@ -1124,6 +1124,26 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [mod_storage_exists](#mod_storage_exists)
|
||||
|
||||
### Lua Example
|
||||
`local booleanValue = mod_storage_exists(key)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| key | `string` |
|
||||
|
||||
### Returns
|
||||
- `boolean`
|
||||
|
||||
### C Prototype
|
||||
`bool mod_storage_exists(const char* key);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [mod_storage_load](#mod_storage_load)
|
||||
|
||||
### Lua Example
|
||||
|
|
|
|||
|
|
@ -1199,6 +1199,7 @@
|
|||
|
||||
- mod_storage.h
|
||||
- [mod_storage_clear](functions-4.md#mod_storage_clear)
|
||||
- [mod_storage_exists](functions-4.md#mod_storage_exists)
|
||||
- [mod_storage_load](functions-4.md#mod_storage_load)
|
||||
- [mod_storage_load_bool](functions-4.md#mod_storage_load_bool)
|
||||
- [mod_storage_load_number](functions-4.md#mod_storage_load_number)
|
||||
|
|
|
|||
|
|
@ -20756,6 +20756,23 @@ int smlua_func_mod_storage_clear(UNUSED lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_mod_storage_exists(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", "mod_storage_exists", 1, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* key = smlua_to_string(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "mod_storage_exists"); return 0; }
|
||||
|
||||
lua_pushboolean(L, mod_storage_exists(key));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_mod_storage_load(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
|
|
@ -34556,6 +34573,7 @@ void smlua_bind_functions_autogen(void) {
|
|||
|
||||
// mod_storage.h
|
||||
smlua_bind_function(L, "mod_storage_clear", smlua_func_mod_storage_clear);
|
||||
smlua_bind_function(L, "mod_storage_exists", smlua_func_mod_storage_exists);
|
||||
smlua_bind_function(L, "mod_storage_load", smlua_func_mod_storage_load);
|
||||
smlua_bind_function(L, "mod_storage_load_bool", smlua_func_mod_storage_load_bool);
|
||||
smlua_bind_function(L, "mod_storage_load_number", smlua_func_mod_storage_load_number);
|
||||
|
|
|
|||
|
|
@ -145,6 +145,22 @@ C_FIELD bool mod_storage_load_bool(const char* key) {
|
|||
return !strcmp(value, "true");
|
||||
}
|
||||
|
||||
C_FIELD bool mod_storage_exists(const char* key) {
|
||||
if (gLuaActiveMod == NULL) { return false; }
|
||||
if (strlen(key) > MAX_KEY_VALUE_LENGTH) { return false; }
|
||||
if (!char_valid((char *)key)) { return false; }
|
||||
|
||||
char filename[SYS_MAX_PATH] = { 0 };
|
||||
mod_storage_get_filename(filename);
|
||||
if (!fs_sys_path_exists(filename)) { return false; }
|
||||
|
||||
mINI::INIFile file(filename);
|
||||
mINI::INIStructure ini;
|
||||
file.read(ini);
|
||||
|
||||
return ini["storage"].has(key);
|
||||
}
|
||||
|
||||
C_FIELD bool mod_storage_remove(const char* key) {
|
||||
if (gLuaActiveMod == NULL) { return false; }
|
||||
if (strlen(key) > MAX_KEY_VALUE_LENGTH) { return false; }
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ const char *mod_storage_load(const char* key);
|
|||
f32 mod_storage_load_number(const char* key);
|
||||
bool mod_storage_load_bool(const char* key);
|
||||
|
||||
bool mod_storage_exists(const char* key);
|
||||
bool mod_storage_remove(const char* key);
|
||||
bool mod_storage_clear(void);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue