From f4c7dc933d0df00c8ecc9308553a135a998399e2 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 21 Oct 2021 22:26:27 -0400 Subject: [PATCH] lua add ability to pass PLUGIN_ ret vals with os.exit() + add defines Change-Id: I45998245271fbd8fee4534f8497b014025e4dcc7 --- apps/plugins/lua/rbdefines_helper.pl | 1 + apps/plugins/lua/rocklua.c | 12 +++++++++--- apps/plugins/lua_scripts/return2WPS.lua | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 apps/plugins/lua_scripts/return2WPS.lua diff --git a/apps/plugins/lua/rbdefines_helper.pl b/apps/plugins/lua/rbdefines_helper.pl index e788855e87..5fb0946a6a 100755 --- a/apps/plugins/lua/rbdefines_helper.pl +++ b/apps/plugins/lua/rbdefines_helper.pl @@ -50,6 +50,7 @@ if ($def_type eq "rb_defines") { '^SYS_(TIMEOUT|POWEROFF|BATTERY_UPDATE)$', '^SYS_USB_(DIS|)CONNECTED$', '^HOME_DIR$', + '^PLUGIN(_OK|_USB_CONNECTED|_POWEROFF|_GOTO_WPS|_GOTO_PLUGIN)$', '^PLUGIN_DIR$', '^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$', '^ROCKBOX_DIR$', diff --git a/apps/plugins/lua/rocklua.c b/apps/plugins/lua/rocklua.c index 3909f3008f..3cf0fce945 100644 --- a/apps/plugins/lua/rocklua.c +++ b/apps/plugins/lua/rocklua.c @@ -175,9 +175,10 @@ static int loadfile_newstate(lua_State **L, const char *filename) static void lua_atexit(void) { char *filename; - + int err_n; if(Ls && lua_gettop(Ls) > 1) { + err_n = lua_tointeger(Ls, -1); /* os.exit? */ if (Ls == lua_touserdata(Ls, -1)) /* signal from restart_lua */ { filename = (char *) malloc((MAX_PATH * 2) + 1); @@ -195,7 +196,12 @@ static void lua_atexit(void) free(filename); plugin_start(NULL); } - else if (lua_tointeger(Ls, -1) != 0) /* os.exit */ + else if (err_n >= PLUGIN_USB_CONNECTED) /* INTERNAL PLUGIN RETVAL */ + { + lua_close(Ls); + _exit(err_n); /* don't call exit handler */ + } + else if (err_n != 0) { ERR_RUN: lu_status = LUA_ERRRUN; @@ -205,7 +211,7 @@ ERR_RUN: else lua_close(Ls); } - _exit(0); /* don't call exit handler */ + _exit(PLUGIN_OK); /* don't call exit handler */ } /* split filename at argchar diff --git a/apps/plugins/lua_scripts/return2WPS.lua b/apps/plugins/lua_scripts/return2WPS.lua new file mode 100644 index 0000000000..9202237691 --- /dev/null +++ b/apps/plugins/lua_scripts/return2WPS.lua @@ -0,0 +1,19 @@ +--[[ + __________ __ ___. + Open \______ \ ____ ____ | | _\_ |__ _______ ___ + Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + \/ \/ \/ \/ \/ + $Id$ + Example Lua Return to WPS on exit + Copyright (C) 2021 William Wilgus + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + KIND, either express or implied. +]]-- + +os.exit(rb.PLUGIN_GOTO_WPS)