summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-11 00:10:25 +0100
committerwm4 <wm4@nowhere>2014-02-11 00:10:25 +0100
commit444f79d86f5483a35f83d3a5efc9cea859f88bf8 (patch)
treea22722153402bd83642945a97120cd25a5fa4549 /player
parent7a53dd5f2fc5990691f1f2353513b33e29f833aa (diff)
downloadmpv-444f79d86f5483a35f83d3a5efc9cea859f88bf8.tar.bz2
mpv-444f79d86f5483a35f83d3a5efc9cea859f88bf8.tar.xz
lua: change error behavior
Return the error Lua-style, instead of raising it as Lua error. This is better, because raising errors is reserved for more "fatal" conditions. Pretending they're exceptions and trying to do exception-style error handling will just lead to pain in this language.
Diffstat (limited to 'player')
-rw-r--r--player/lua.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/player/lua.c b/player/lua.c
index 0a3ef775ad..e7ff414298 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -94,14 +94,17 @@ static void report_error(lua_State *L)
}
// Check client API error code:
-// if err >= 0, return 0.
-// if err < 0, raise the error as Lua error.
+// if err >= 0, push "true" to the stack, and return 1
+// if err < 0, push nil and then the error string to the stack, and return 2
static int check_error(lua_State *L, int err)
{
- if (err >= 0)
- return 0;
- luaL_error(L, "mpv API error: %s", mpv_error_string(err));
- abort();
+ if (err >= 0) {
+ lua_pushboolean(L, 1);
+ return 1;
+ }
+ lua_pushnil(L);
+ lua_pushstring(L, mpv_error_string(err));
+ return 2;
}
static int run_event_loop(lua_State *L)
@@ -491,16 +494,11 @@ static int script_get_property(lua_State *L)
talloc_free(result);
return 1;
}
- // out of convenience, property access errors are not hard errors
- if (err != MPV_ERROR_PROPERTY_NOT_FOUND &&
- err != MPV_ERROR_PROPERTY_ERROR &&
- err != MPV_ERROR_PROPERTY_UNAVAILABLE)
- check_error(L, err);
if (type == MPV_FORMAT_OSD_STRING) {
lua_pushstring(L, "");
- return 1;
+ lua_pushstring(L, mpv_error_string(err));
}
- return 0;
+ return check_error(L, err);
}
static int script_set_osd_ass(lua_State *L)