aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lauxlib.c9
-rw-r--r--ltests.c5
-rw-r--r--manual/manual.of4
3 files changed, 14 insertions, 4 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 4ca6c654..1c9082e6 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1025,9 +1025,14 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
1025} 1025}
1026 1026
1027 1027
1028/*
1029** Standard panic funcion just prints an error message. The test
1030** with 'lua_type' avoids possible memory errors in 'lua_tostring'.
1031*/
1028static int panic (lua_State *L) { 1032static int panic (lua_State *L) {
1029 const char *msg = lua_tostring(L, -1); 1033 const char *msg = (lua_type(L, -1) == LUA_TSTRING)
1030 if (msg == NULL) msg = "error object is not a string"; 1034 ? lua_tostring(L, -1)
1035 : "error object is not a string";
1031 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", 1036 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
1032 msg); 1037 msg);
1033 return 0; /* return to Lua to abort */ 1038 return 0; /* return to Lua to abort */
diff --git a/ltests.c b/ltests.c
index 7d184c0d..c2943a4f 100644
--- a/ltests.c
+++ b/ltests.c
@@ -73,8 +73,9 @@ static void badexit (const char *fmt, const char *s1, const char *s2) {
73 73
74 74
75static int tpanic (lua_State *L) { 75static int tpanic (lua_State *L) {
76 const char *msg = lua_tostring(L, -1); 76 const char *msg = (lua_type(L, -1) == LUA_TSTRING)
77 if (msg == NULL) msg = "error object is not a string"; 77 ? lua_tostring(L, -1)
78 : "error object is not a string";
78 return (badexit("PANIC: unprotected error in call to Lua API (%s)\n", 79 return (badexit("PANIC: unprotected error in call to Lua API (%s)\n",
79 msg, NULL), 80 msg, NULL),
80 0); /* do not return to Lua */ 81 0); /* do not return to Lua */
diff --git a/manual/manual.of b/manual/manual.of
index ad120f5e..cef3e22a 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -4486,6 +4486,10 @@ This string always has a zero (@Char{\0})
4486after its last character (as @N{in C}), 4486after its last character (as @N{in C}),
4487but can contain other zeros in its body. 4487but can contain other zeros in its body.
4488 4488
4489This function can raise memory errors only
4490when converting a number to a string
4491(as then it has to create a new string).
4492
4489} 4493}
4490 4494
4491@APIEntry{lua_Number lua_tonumber (lua_State *L, int index);| 4495@APIEntry{lua_Number lua_tonumber (lua_State *L, int index);|