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.
This commit is contained in:
Niels Martin Hansen 2008-09-10 16:53:23 +00:00
parent 30a0b7e82b
commit e737471043
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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);