From ffe5558ba165fdd9a52f9efe8fcfe01b1c681475 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Thu, 15 Feb 2007 12:56:36 +0000 Subject: [PATCH] Added VFR handling functions to Auto4/Lua. Originally committed to SVN as r937. --- aegisub/auto4_lua.cpp | 31 +++++++++++++++++++++++++++++++ aegisub/auto4_lua.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/aegisub/auto4_lua.cpp b/aegisub/auto4_lua.cpp index de743d101..9d03a2557 100644 --- a/aegisub/auto4_lua.cpp +++ b/aegisub/auto4_lua.cpp @@ -226,6 +226,11 @@ namespace Automation4 { // aegisub.text_extents lua_pushcfunction(L, LuaTextExtents); lua_setfield(L, -2, "text_extents"); + // VFR handling + lua_pushcfunction(L, LuaFrameFromMs); + lua_setfield(L, -2, "frame_from_ms"); + lua_pushcfunction(L, LuaMsFromFrame); + lua_setfield(L, -2, "ms_from_frame"); // aegisub.lua_automation_version lua_pushinteger(L, 4); lua_setfield(L, -2, "lua_automation_version"); @@ -416,6 +421,32 @@ namespace Automation4 { return lua_gettop(L) - pretop; } + int LuaScript::LuaFrameFromMs(lua_State *L) + { + int ms = (int)lua_tonumber(L, -1); + lua_pop(L, 1); + if (VFR_Output.IsLoaded()) { + lua_pushnumber(L, VFR_Output.GetFrameAtTime(ms, true)); + return 1; + } else { + lua_pushnil(L); + return 1; + } + } + + int LuaScript::LuaMsFromFrame(lua_State *L) + { + int frame = (int)lua_tonumber(L, -1); + lua_pop(L, 1); + if (VFR_Output.IsLoaded()) { + lua_pushnumber(L, VFR_Output.GetTimeAtFrame(frame, true)); + return 1; + } else { + lua_pushnil(L); + return 1; + } + } + // LuaThreadedCall diff --git a/aegisub/auto4_lua.h b/aegisub/auto4_lua.h index 5e876cafc..d0b314ed9 100644 --- a/aegisub/auto4_lua.h +++ b/aegisub/auto4_lua.h @@ -191,6 +191,8 @@ namespace Automation4 { static int LuaTextExtents(lua_State *L); static int LuaInclude(lua_State *L); + static int LuaFrameFromMs(lua_State *L); + static int LuaMsFromFrame(lua_State *L); public: LuaScript(const wxString &filename);