summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-12 14:52:14 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-15 18:56:25 +1000
commit4a0aa6eecf10432453c22031c247cf24819f1040 (patch)
tree542bf773168d6af2069a91125447801a5576d2c6 /tests
parent424a3604dd90a40773e3434450bb5cb685962926 (diff)
downloadfengari-4a0aa6eecf10432453c22031c247cf24819f1040.tar.gz
fengari-4a0aa6eecf10432453c22031c247cf24819f1040.tar.bz2
fengari-4a0aa6eecf10432453c22031c247cf24819f1040.zip
Add facility for a user provided (state-global) native error handler
Diffstat (limited to 'tests')
-rw-r--r--tests/lapi.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/lapi.js b/tests/lapi.js
index b739860..1dbdd5c 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -481,3 +481,43 @@ test('lua_settable, lua_gettable', function (t) {
"Correct element(s) on the stack"
);
});
+
+test('lua_atnativeerror', function(t) {
+ t.plan(7);
+
+ let L = lauxlib.luaL_newstate();
+ let errob = {};
+
+ lua.lua_pushcfunction(L, function(L) {
+ throw errob;
+ });
+ t.strictEqual(lua.lua_pcall(L, 0, 0, 0), -1, "without a native error handler pcall should be -1");
+ lua.lua_pop(L, 1);
+
+
+ lua.lua_atnativeerror(L, function(L) {
+ let e = lua.lua_touserdata(L, 1);
+ t.strictEqual(e, errob);
+ lua.lua_pushstring(L, lua.to_luastring("runtime error!"));
+ return 1;
+ });
+ lua.lua_pushcfunction(L, function(L) {
+ throw errob;
+ });
+ t.strictEqual(lua.lua_pcall(L, 0, 0, 0), lua.LUA_ERRRUN, "should return lua.LUA_ERRRUN");
+ t.strictEqual(lua.lua_tojsstring(L, -1), "runtime error!");
+ lua.lua_pop(L, 1);
+
+
+ lua.lua_atnativeerror(L, function(L) {
+ let e = lua.lua_touserdata(L, 1);
+ t.strictEqual(e, errob);
+ lauxlib.luaL_error(L, lua.to_luastring("runtime error!"));
+ });
+ lua.lua_pushcfunction(L, function(L) {
+ throw errob;
+ });
+ t.strictEqual(lua.lua_pcall(L, 0, 0, 0), lua.LUA_ERRRUN, "luaL_error from a native error handler should result in LUA_ERRRUN");
+ t.strictEqual(lua.lua_tojsstring(L, -1), "runtime error!");
+ lua.lua_pop(L, 1);
+});