From 46f5079a63b35b258f1bb099392e1ef717cdd588 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Mon, 23 Aug 2021 23:32:13 +1000 Subject: [PATCH] Fixed panic handling on REPL input. The Lua debug module is mandatory now. --- components/lua/Kconfig | 3 ++- components/lua/common/lpanic.c | 4 +++- components/lua/common/lpanic.h | 2 +- components/lua/lua-5.1/lauxlib.c | 2 +- components/lua/lua-5.3/lauxlib.c | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/components/lua/Kconfig b/components/lua/Kconfig index 025a6efc..8cb8d9dd 100644 --- a/components/lua/Kconfig +++ b/components/lua/Kconfig @@ -72,7 +72,7 @@ menu "Lua configuration" bool "UTF8 module" default "y" help - Includes the debug module. + Includes the debug module (required by our Lua VM). config LUA_BUILTIN_DEBUG bool "Debug module" @@ -124,5 +124,6 @@ menu "Lua configuration" default y select NODEMCU_CMODULE_PIPE select NODEMCU_CMODULE_UART + select LUA_BUILTIN_DEBUG endmenu diff --git a/components/lua/common/lpanic.c b/components/lua/common/lpanic.c index b44486c7..d8e9a491 100644 --- a/components/lua/common/lpanic.c +++ b/components/lua/common/lpanic.c @@ -2,6 +2,7 @@ #include "lauxlib.h" #include #include +#include #ifndef LUA_CROSS_COMPILER #include "esp_system.h" /* defined in esp_system_internal.h */ @@ -33,7 +34,7 @@ int panic_get_nvval() { #endif -int panic (lua_State *L) { +int lpanic (lua_State *L) { (void)L; /* to avoid warnings */ #ifndef LUA_CROSS_COMPILER uint8_t paniclevel = panic_get_nvval(); @@ -43,6 +44,7 @@ int panic (lua_State *L) { lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", lua_tostring(L, -1)); #ifndef LUA_CROSS_COMPILER + fflush(stdout); /* call abort() directly - we don't want another reset cause to intervene */ esp_reset_reason_set_hint(ESP_RST_PANIC); #endif diff --git a/components/lua/common/lpanic.h b/components/lua/common/lpanic.h index bb9fcb97..6caf7103 100644 --- a/components/lua/common/lpanic.h +++ b/components/lua/common/lpanic.h @@ -5,6 +5,6 @@ void panic_clear_nvval (void); int panic_get_nvval (void); -int panic (lua_State *L); +int lpanic (lua_State *L); #endif diff --git a/components/lua/lua-5.1/lauxlib.c b/components/lua/lua-5.1/lauxlib.c index 5bc06b0f..82c99c1c 100644 --- a/components/lua/lua-5.1/lauxlib.c +++ b/components/lua/lua-5.1/lauxlib.c @@ -917,7 +917,7 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message) LUALIB_API lua_State *luaL_newstate (void) { lua_State *L = lua_newstate(l_alloc, NULL); lua_setallocf(L, l_alloc, L); /* allocator need lua_State. */ - if (L) lua_atpanic(L, &panic); + if (L) lua_atpanic(L, lpanic); return L; } diff --git a/components/lua/lua-5.3/lauxlib.c b/components/lua/lua-5.3/lauxlib.c index 9abf4c6b..30c34144 100644 --- a/components/lua/lua-5.3/lauxlib.c +++ b/components/lua/lua-5.3/lauxlib.c @@ -1104,7 +1104,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { LUALIB_API lua_State *luaL_newstate (void) { lua_State *L = lua_newstate(l_alloc, NULL); - if (L) lua_atpanic(L, &panic); + if (L) lua_atpanic(L, lpanic); return L; }