]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
From Lua 5.3: assert() accepts any type of error object.
authorMike Pall <mike>
Tue, 5 Jun 2018 10:23:56 +0000 (12:23 +0200)
committerMike Pall <mike>
Tue, 5 Jun 2018 10:23:56 +0000 (12:23 +0200)
doc/extensions.html
src/lib_base.c

index 55c4b704ed59f10d0c7cb52cf6160d449d39dece..7379041d4c0eb11bdf42690b94514cee47887ece 100644 (file)
@@ -373,6 +373,7 @@ LuaJIT supports some extensions from Lua&nbsp;5.3:
 <li>Unicode escape <tt>'\u{XX...}'</tt> embeds the UTF-8 encoding in string literals.</li>
 <li>The argument table <tt>arg</tt> can be read (and modified) by <tt>LUA_INIT</tt> and <tt>-e</tt> chunks.</li>
 <li><tt>io.read()</tt> and <tt>file:read()</tt> accept formats with or without a leading <tt>*</tt>.</li>
+<li><tt>assert()</tt> accepts any type of error object.</li>
 <li><tt>table.move(a1, f, e, t [,a2])</tt>.</li>
 <li><tt>coroutine.isyieldable()</tt>.</li>
 <li>Lua/C API extensions:
index d61e8762f6afc9cc4ea6927ce73d6c8aebb00cc7..1cd830585eab2633f1af069f5c05b2e69f1a862f 100644 (file)
 
 LJLIB_ASM(assert)              LJLIB_REC(.)
 {
-  GCstr *s;
   lj_lib_checkany(L, 1);
-  s = lj_lib_optstr(L, 2);
-  if (s)
-    lj_err_callermsg(L, strdata(s));
-  else
+  if (L->top == L->base+1)
     lj_err_caller(L, LJ_ERR_ASSERT);
+  else if (tvisstr(L->base+1) || tvisnumber(L->base+1))
+    lj_err_callermsg(L, strdata(lj_lib_checkstr(L, 2)));
+  else
+    lj_err_run(L);
   return FFH_UNREACHABLE;
 }