aboutsummaryrefslogtreecommitdiff
path: root/src/lbaselib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 13:54:30 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 13:54:30 +0100
commitb31cc0420e77d34465e4cf7d7ab75df7755b44d6 (patch)
tree6d908904fc1679549293bbe314550ec7dff82a2a /src/lbaselib.js
parent290ec54e13d1dff301465cbfa2fd7b4e1e52962f (diff)
downloadfengari-b31cc0420e77d34465e4cf7d7ab75df7755b44d6.tar.gz
fengari-b31cc0420e77d34465e4cf7d7ab75df7755b44d6.tar.bz2
fengari-b31cc0420e77d34465e4cf7d7ab75df7755b44d6.zip
assert
Diffstat (limited to 'src/lbaselib.js')
-rw-r--r--src/lbaselib.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 9cc4fb1..fa0349b 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -165,6 +165,18 @@ const luaB_error = function(L) {
return lapi.lua_error(L);
};
+const luaB_assert = function(L) {
+ if (lapi.lua_toboolean(L, 1)) /* condition is true? */
+ return lapi.lua_gettop(L); /* return all arguments */
+ else {
+ lauxlib.luaL_checkany(L, 1); /* there must be a condition */
+ lapi.lua_remove(L, 1); /* remove it */
+ lapi.lua_pushliteral(L, "assertion failed!"); /* default message */
+ lapi.lua_settop(L, 1); /* leave only message (default if no other one) */
+ return luaB_error(L); /* call 'error' */
+ }
+};
+
const luaB_select = function(L) {
let n = lapi.lua_gettop(L);
if (lapi.lua_type(L, 1) === CT.LUA_TSTRING && lapi.lua_tostring(L, 1) === "#") {
@@ -220,6 +232,7 @@ const luaB_xpcall = function(L) {
const base_funcs = {
"collectgarbage": function () {},
+ "assert": luaB_assert,
"print": luaB_print,
"tostring": luaB_tostring,
"tonumber": luaB_tonumber,