0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-27 04:43:52 +01:00

make lua work on return

This commit is contained in:
2025-12-22 15:03:12 +01:00
parent f2dcf8563c
commit 1a747d9264
2 changed files with 18 additions and 25 deletions

View File

@@ -24,20 +24,17 @@ void run_lua(char *str, char *cmd_output) {
char path[128];
snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME"));
if (luaL_dofile(L, path) != LUA_OK) {
if (luaL_loadfilex(L, path, NULL) == LUA_OK && lua_pcall(L, 0, 1, 0) == LUA_OK) {
if (lua_isstring(L, -1)) {
const char * message = lua_tostring(L, -1);
if(cmd_output) strcpy(cmd_output, message);
}
lua_pop(L, 1);
} else {
const char *err = lua_tostring(L, -1);
fprintf(stderr, "Lua error: %s\n", err);
lua_pop(L, 1);
lua_settop(L, top);
return;
}
lua_getglobal(L, "cmd_output");
if (lua_isstring(L, -1)) {
const char * message = lua_tostring(L, -1);
lua_pop(L, 1);
if(cmd_output) strcpy(cmd_output, message);
}
}