From 212d4e6061463e44e9333d7d0b99f10733bee22e Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 11 Feb 2014 00:57:40 +0100 Subject: lua: some minor API changes --- player/lua.c | 27 +++++++++++++++------------ player/lua/defaults.lua | 7 +++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/player/lua.c b/player/lua.c index 922b49417a..60cf4d2fcf 100644 --- a/player/lua.c +++ b/player/lua.c @@ -354,18 +354,20 @@ static int script_suspend(lua_State *L) static int script_resume(lua_State *L) { struct script_ctx *ctx = get_ctx(L); - static const char *modes[] = {"normal", "all", NULL}; - if (luaL_checkoption(L, 1, "normal", modes) == 1) { - if (ctx->suspended) - mpv_resume(ctx->client); - ctx->suspended = 0; - } else { - if (ctx->suspended < 1) - luaL_error(L, "trying to resume, but core is not suspended"); - ctx->suspended--; - if (!ctx->suspended) - mpv_resume(ctx->client); - } + if (ctx->suspended < 1) + luaL_error(L, "trying to resume, but core is not suspended"); + ctx->suspended--; + if (!ctx->suspended) + mpv_resume(ctx->client); + return 0; +} + +static int script_resume_all(lua_State *L) +{ + struct script_ctx *ctx = get_ctx(L); + if (ctx->suspended) + mpv_resume(ctx->client); + ctx->suspended = 0; return 0; } @@ -738,6 +740,7 @@ static struct fn_entry fn_list[] = { FN_ENTRY(log), FN_ENTRY(suspend), FN_ENTRY(resume), + FN_ENTRY(resume_all), FN_ENTRY(wait_event), FN_ENTRY(request_event), FN_ENTRY(find_config_file), diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 88270253c8..1ab1c4264a 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -1,3 +1,6 @@ +function mp.get_script_name() + return mp.script_name +end local callbacks = {} -- each script has its own section, so that they don't conflict @@ -133,7 +136,7 @@ local event_handlers = {} function mp.register_event(name, cb) event_handlers[name] = cb - mp.request_event(name, true) + return mp.request_event(name, true) end -- default handlers @@ -169,7 +172,7 @@ _G.mp_event_loop = function() -- Resume playloop - important especially if an error happened while -- suspended, and the error was handled, but no resume was done. if wait > 0 then - mp.resume("all") + mp.resume_all() end local e = mp.wait_event(wait) -- Empty the event queue while suspended; otherwise, each -- cgit v1.2.3