smlua_exec_str (run Lua from string)

Seemed useful for debug or any other purposes, why not?
This commit is contained in:
Agent X 2023-03-08 18:54:06 -05:00
parent 07e0f31a38
commit db38b3d55d
6 changed files with 49 additions and 1 deletions

View File

@ -8418,6 +8418,12 @@ function set_override_near(near)
-- ...
end
--- @param str string
--- @return nil
function smlua_exec_str(str)
-- ...
end
--- @param name string
--- @return integer
function smlua_model_util_get_id(name)

View File

@ -8658,6 +8658,26 @@
<br />
## [smlua_exec_str](#smlua_exec_str)
### Lua Example
`smlua_exec_str(str)`
### Parameters
| Field | Type |
| ----- | ---- |
| str | `string` |
### Returns
- None
### C Prototype
`void smlua_exec_str(const char* str);`
[:arrow_up_small:](#)
<br />
---
# functions from smlua_model_utils.h

View File

@ -1560,6 +1560,7 @@
- [set_override_far](functions-4.md#set_override_far)
- [set_override_fov](functions-4.md#set_override_fov)
- [set_override_near](functions-4.md#set_override_near)
- [smlua_exec_str](functions-4.md#smlua_exec_str)
<br />

View File

@ -7,6 +7,7 @@
#include "pc/lua/utils/smlua_audio_utils.h"
#include "pc/lua/utils/smlua_model_utils.h"
#include "pc/lua/utils/smlua_level_utils.h"
#include "pc/lua/utils/smlua_misc_utils.h"
#include "pc/djui/djui.h"
lua_State* gLuaState = NULL;
@ -52,7 +53,7 @@ static void smlua_exec_file(char* path) {
lua_pop(L, lua_gettop(L));
}
static void smlua_exec_str(char* str) {
void smlua_exec_str(const char* str) {
lua_State* L = gLuaState;
if (luaL_dostring(L, str) != LUA_OK) {
LOG_LUA("Failed to load lua string.");

View File

@ -27411,6 +27411,23 @@ int smlua_func_set_override_near(lua_State* L) {
return 1;
}
int smlua_func_smlua_exec_str(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", "smlua_exec_str", 1, top);
return 0;
}
const char* str = smlua_to_string(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "smlua_exec_str"); return 0; }
smlua_exec_str(str);
return 1;
}
/////////////////////////
// smlua_model_utils.h //
/////////////////////////
@ -30370,6 +30387,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "set_override_far", smlua_func_set_override_far);
smlua_bind_function(L, "set_override_fov", smlua_func_set_override_fov);
smlua_bind_function(L, "set_override_near", smlua_func_set_override_near);
smlua_bind_function(L, "smlua_exec_str", smlua_func_smlua_exec_str);
// smlua_model_utils.h
smlua_bind_function(L, "smlua_model_util_get_id", smlua_func_smlua_model_util_get_id);

View File

@ -96,4 +96,6 @@ void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue);
bool course_is_main_course(u16 levelNum);
void smlua_exec_str(const char* str);
#endif