|
 |
006bc1 |
From a5a89ab586a3b5bb4f266949bbf3dc2b140e2374 Mon Sep 17 00:00:00 2001
|
|
 |
006bc1 |
From: Mike Pall <mike>
|
|
 |
006bc1 |
Date: Tue, 5 Jun 2018 12:23:56 +0200
|
|
 |
006bc1 |
Subject: [PATCH 44/72] From Lua 5.3: assert() accepts any type of error
|
|
 |
006bc1 |
object.
|
|
 |
006bc1 |
|
|
 |
006bc1 |
---
|
|
 |
006bc1 |
doc/extensions.html | 1 +
|
|
 |
006bc1 |
src/lib_base.c | 10 +++++-----
|
|
 |
006bc1 |
2 files changed, 6 insertions(+), 5 deletions(-)
|
|
 |
006bc1 |
|
|
 |
006bc1 |
diff --git a/doc/extensions.html b/doc/extensions.html
|
|
 |
006bc1 |
index 55c4b70..7379041 100644
|
|
 |
006bc1 |
--- a/doc/extensions.html
|
|
 |
006bc1 |
+++ b/doc/extensions.html
|
|
 |
006bc1 |
@@ -373,6 +373,7 @@ LuaJIT supports some extensions from Lua 5.3:
|
|
 |
006bc1 |
Unicode escape <tt>'\u{XX...}'</tt> embeds the UTF-8 encoding in string literals.
|
|
 |
006bc1 |
The argument table <tt>arg</tt> can be read (and modified) by <tt>LUA_INIT</tt> and <tt>-e</tt> chunks.
|
|
 |
006bc1 |
<tt>io.read()</tt> and <tt>file:read()</tt> accept formats with or without a leading <tt>*</tt>.
|
|
 |
006bc1 |
+<tt>assert()</tt> accepts any type of error object.
|
|
 |
006bc1 |
<tt>table.move(a1, f, e, t [,a2])</tt>.
|
|
 |
006bc1 |
<tt>coroutine.isyieldable()</tt>.
|
|
 |
006bc1 |
Lua/C API extensions:
|
|
 |
006bc1 |
diff --git a/src/lib_base.c b/src/lib_base.c
|
|
 |
006bc1 |
index d61e876..1cd8305 100644
|
|
 |
006bc1 |
--- a/src/lib_base.c
|
|
 |
006bc1 |
+++ b/src/lib_base.c
|
|
 |
006bc1 |
@@ -42,13 +42,13 @@
|
|
 |
006bc1 |
|
|
 |
006bc1 |
LJLIB_ASM(assert) LJLIB_REC(.)
|
|
 |
006bc1 |
{
|
|
 |
006bc1 |
- GCstr *s;
|
|
 |
006bc1 |
lj_lib_checkany(L, 1);
|
|
 |
006bc1 |
- s = lj_lib_optstr(L, 2);
|
|
 |
006bc1 |
- if (s)
|
|
 |
006bc1 |
- lj_err_callermsg(L, strdata(s));
|
|
 |
006bc1 |
- else
|
|
 |
006bc1 |
+ if (L->top == L->base+1)
|
|
 |
006bc1 |
lj_err_caller(L, LJ_ERR_ASSERT);
|
|
 |
006bc1 |
+ else if (tvisstr(L->base+1) || tvisnumber(L->base+1))
|
|
 |
006bc1 |
+ lj_err_callermsg(L, strdata(lj_lib_checkstr(L, 2)));
|
|
 |
006bc1 |
+ else
|
|
 |
006bc1 |
+ lj_err_run(L);
|
|
 |
006bc1 |
return FFH_UNREACHABLE;
|
|
 |
006bc1 |
}
|
|
 |
006bc1 |
|
|
 |
006bc1 |
--
|
|
 |
006bc1 |
2.20.1
|
|
 |
006bc1 |
|