lua: some minor API changes

This commit is contained in:
wm4 2014-02-11 00:57:40 +01:00
parent 33c6cbef3a
commit 212d4e6061
2 changed files with 20 additions and 14 deletions

View File

@ -354,18 +354,20 @@ static int script_suspend(lua_State *L)
static int script_resume(lua_State *L) static int script_resume(lua_State *L)
{ {
struct script_ctx *ctx = get_ctx(L); struct script_ctx *ctx = get_ctx(L);
static const char *modes[] = {"normal", "all", NULL}; if (ctx->suspended < 1)
if (luaL_checkoption(L, 1, "normal", modes) == 1) { luaL_error(L, "trying to resume, but core is not suspended");
if (ctx->suspended) ctx->suspended--;
mpv_resume(ctx->client); if (!ctx->suspended)
ctx->suspended = 0; mpv_resume(ctx->client);
} else { return 0;
if (ctx->suspended < 1) }
luaL_error(L, "trying to resume, but core is not suspended");
ctx->suspended--; static int script_resume_all(lua_State *L)
if (!ctx->suspended) {
mpv_resume(ctx->client); struct script_ctx *ctx = get_ctx(L);
} if (ctx->suspended)
mpv_resume(ctx->client);
ctx->suspended = 0;
return 0; return 0;
} }
@ -738,6 +740,7 @@ static struct fn_entry fn_list[] = {
FN_ENTRY(log), FN_ENTRY(log),
FN_ENTRY(suspend), FN_ENTRY(suspend),
FN_ENTRY(resume), FN_ENTRY(resume),
FN_ENTRY(resume_all),
FN_ENTRY(wait_event), FN_ENTRY(wait_event),
FN_ENTRY(request_event), FN_ENTRY(request_event),
FN_ENTRY(find_config_file), FN_ENTRY(find_config_file),

View File

@ -1,3 +1,6 @@
function mp.get_script_name()
return mp.script_name
end
local callbacks = {} local callbacks = {}
-- each script has its own section, so that they don't conflict -- 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) function mp.register_event(name, cb)
event_handlers[name] = cb event_handlers[name] = cb
mp.request_event(name, true) return mp.request_event(name, true)
end end
-- default handlers -- default handlers
@ -169,7 +172,7 @@ _G.mp_event_loop = function()
-- Resume playloop - important especially if an error happened while -- Resume playloop - important especially if an error happened while
-- suspended, and the error was handled, but no resume was done. -- suspended, and the error was handled, but no resume was done.
if wait > 0 then if wait > 0 then
mp.resume("all") mp.resume_all()
end end
local e = mp.wait_event(wait) local e = mp.wait_event(wait)
-- Empty the event queue while suspended; otherwise, each -- Empty the event queue while suspended; otherwise, each