diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-02-28 14:53:58 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-02-28 14:53:58 -0300 |
commit | ee99452158de5e2fa804bd10de7669848f3b3952 (patch) | |
tree | a68b8834ef0f61f9a7a2ce297ab3963cec8e56d9 /ldo.c | |
parent | 127a8e80fe0d74efd26994b3877cdc77b712ea56 (diff) | |
download | lua-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.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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 | ||