Add mod_storage_exists

This commit is contained in:
Agent X 2024-12-05 18:28:57 -05:00
parent bff0cda663
commit 856a828229
6 changed files with 62 additions and 0 deletions

View file

@ -5389,6 +5389,12 @@ function mod_storage_clear()
-- ... -- ...
end end
--- @param key string
--- @return boolean
function mod_storage_exists(key)
-- ...
end
--- @param key string --- @param key string
--- @return string --- @return string
function mod_storage_load(key) function mod_storage_load(key)

View file

@ -1124,6 +1124,26 @@
<br /> <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) ## [mod_storage_load](#mod_storage_load)
### Lua Example ### Lua Example

View file

@ -1199,6 +1199,7 @@
- mod_storage.h - mod_storage.h
- [mod_storage_clear](functions-4.md#mod_storage_clear) - [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](functions-4.md#mod_storage_load)
- [mod_storage_load_bool](functions-4.md#mod_storage_load_bool) - [mod_storage_load_bool](functions-4.md#mod_storage_load_bool)
- [mod_storage_load_number](functions-4.md#mod_storage_load_number) - [mod_storage_load_number](functions-4.md#mod_storage_load_number)

View file

@ -20756,6 +20756,23 @@ int smlua_func_mod_storage_clear(UNUSED lua_State* L) {
return 1; 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) { int smlua_func_mod_storage_load(lua_State* L) {
if (L == NULL) { return 0; } if (L == NULL) { return 0; }
@ -34556,6 +34573,7 @@ void smlua_bind_functions_autogen(void) {
// mod_storage.h // mod_storage.h
smlua_bind_function(L, "mod_storage_clear", smlua_func_mod_storage_clear); 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", 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_bool", smlua_func_mod_storage_load_bool);
smlua_bind_function(L, "mod_storage_load_number", smlua_func_mod_storage_load_number); smlua_bind_function(L, "mod_storage_load_number", smlua_func_mod_storage_load_number);

View file

@ -145,6 +145,22 @@ C_FIELD bool mod_storage_load_bool(const char* key) {
return !strcmp(value, "true"); 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) { C_FIELD bool mod_storage_remove(const char* key) {
if (gLuaActiveMod == NULL) { return false; } if (gLuaActiveMod == NULL) { return false; }
if (strlen(key) > MAX_KEY_VALUE_LENGTH) { return false; } if (strlen(key) > MAX_KEY_VALUE_LENGTH) { return false; }

View file

@ -20,6 +20,7 @@ const char *mod_storage_load(const char* key);
f32 mod_storage_load_number(const char* key); f32 mod_storage_load_number(const char* key);
bool mod_storage_load_bool(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_remove(const char* key);
bool mod_storage_clear(void); bool mod_storage_clear(void);