From e7374710439079a761d76d20587dcccc62c6724d Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Wed, 10 Sep 2008 16:53:23 +0000 Subject: [PATCH] Implement aegisub.video_size() function in Automation 4 Lua. Returns nil if no video is loaded, otherwise returns xres,yres,ar,artype. Originally committed to SVN as r2337. --- aegisub/auto4_lua.cpp | 19 +++++++++++++++++++ aegisub/auto4_lua.h | 1 + 2 files changed, 20 insertions(+) diff --git a/aegisub/auto4_lua.cpp b/aegisub/auto4_lua.cpp index a9d8e6bdc..4e0239027 100644 --- a/aegisub/auto4_lua.cpp +++ b/aegisub/auto4_lua.cpp @@ -44,7 +44,9 @@ #include "ass_override.h" #include "text_file_reader.h" #include "options.h" + #include "vfr.h" +#include "video_context.h" #ifdef __WINDOWS__ #include "../lua51/src/lualib.h" @@ -177,6 +179,8 @@ namespace Automation4 { lua_setfield(L, -2, "frame_from_ms"); lua_pushcfunction(L, LuaMsFromFrame); lua_setfield(L, -2, "ms_from_frame"); + lua_pushcfunction(L, LuaVideoSize); + lua_setfield(L, -2, "video_size"); // aegisub.lua_automation_version lua_pushinteger(L, 4); lua_setfield(L, -2, "lua_automation_version"); @@ -393,6 +397,21 @@ namespace Automation4 { } } + int LuaScript::LuaVideoSize(lua_State *L) + { + VideoContext *ctx = VideoContext::Get(); + if (ctx->IsLoaded()) { + lua_pushnumber(L, ctx->GetWidth()); + lua_pushnumber(L, ctx->GetHeight()); + lua_pushnumber(L, ctx->GetAspectRatioValue()); + lua_pushnumber(L, ctx->GetAspectRatioType()); + return 4; + } else { + lua_pushnil(L); + return 1; + } + } + // LuaThreadedCall diff --git a/aegisub/auto4_lua.h b/aegisub/auto4_lua.h index 72c90d09b..3c0dadc62 100644 --- a/aegisub/auto4_lua.h +++ b/aegisub/auto4_lua.h @@ -194,6 +194,7 @@ namespace Automation4 { static int LuaInclude(lua_State *L); static int LuaFrameFromMs(lua_State *L); static int LuaMsFromFrame(lua_State *L); + static int LuaVideoSize(lua_State *L); public: LuaScript(const wxString &filename);