Fixed panic handling on REPL input.

The Lua debug module is mandatory now.
This commit is contained in:
Johny Mattsson 2021-08-23 23:32:13 +10:00
parent fbef7feae1
commit 46f5079a63
5 changed files with 8 additions and 5 deletions

View File

@ -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

View File

@ -2,6 +2,7 @@
#include "lauxlib.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#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

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}