aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-02-28 14:53:58 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-02-28 14:53:58 -0300
commitee99452158de5e2fa804bd10de7669848f3b3952 (patch)
treea68b8834ef0f61f9a7a2ce297ab3963cec8e56d9 /ldo.c
parent127a8e80fe0d74efd26994b3877cdc77b712ea56 (diff)
downloadlua-ee99452158de5e2fa804bd10de7669848f3b3952.tar.gz
lua-ee99452158de5e2fa804bd10de7669848f3b3952.tar.bz2
lua-ee99452158de5e2fa804bd10de7669848f3b3952.zip
Error object cannot be nil
Lua will change a nil as error object to a string message, so that it never reports an error with nil as the error object.
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/ldo.c b/ldo.c
index 3ddc5a4c..84f7bbb2 100644
--- a/ldo.c
+++ b/ldo.c
@@ -112,12 +112,16 @@ void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop) {
112 break; 112 break;
113 } 113 }
114 default: { 114 default: {
115 lua_assert(errorstatus(errcode)); /* real error */ 115 lua_assert(errorstatus(errcode)); /* must be a real error */
116 setobjs2s(L, oldtop, L->top.p - 1); /* error message on current top */ 116 if (!ttisnil(s2v(L->top.p - 1))) { /* error object is not nil? */
117 setobjs2s(L, oldtop, L->top.p - 1); /* move it to 'oldtop' */
118 }
119 else /* change it to a proper message */
120 setsvalue2s(L, oldtop, luaS_newliteral(L, "<error object is nil>"));
117 break; 121 break;
118 } 122 }
119 } 123 }
120 L->top.p = oldtop + 1; 124 L->top.p = oldtop + 1; /* top goes back to old top plus error object */
121} 125}
122 126
123 127