Added VFR handling functions to Auto4/Lua.

Originally committed to SVN as r937.
This commit is contained in:
Niels Martin Hansen 2007-02-15 12:56:36 +00:00
parent 30792ec961
commit ffe5558ba1
2 changed files with 33 additions and 0 deletions

View File

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

View File

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