forked from mia/Aegisub
Actually define __ipairs on LuaAssFile
This commit is contained in:
parent
995e0d85e9
commit
b2f5a993d9
2 changed files with 25 additions and 0 deletions
|
@ -93,6 +93,8 @@ namespace Automation4 {
|
|||
void ObjectAppend(lua_State *L);
|
||||
void ObjectInsert(lua_State *L);
|
||||
void ObjectGarbageCollect(lua_State *L);
|
||||
int ObjectIPairs(lua_State *L);
|
||||
int IterNext(lua_State *L);
|
||||
|
||||
int LuaParseKaraokeData(lua_State *L);
|
||||
|
||||
|
|
|
@ -512,6 +512,28 @@ namespace Automation4 {
|
|||
LOG_D("automation/lua") << "Garbage collected LuaAssFile";
|
||||
}
|
||||
|
||||
int LuaAssFile::ObjectIPairs(lua_State *L)
|
||||
{
|
||||
lua_pushvalue(L, lua_upvalueindex(1)); // push 'this' as userdata
|
||||
lua_pushcclosure(L, closure_wrapper<&LuaAssFile::IterNext>, 1);
|
||||
lua_pushnil(L);
|
||||
push_value(L, 0);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int LuaAssFile::IterNext(lua_State *L)
|
||||
{
|
||||
int i = luaL_checkint(L, 2);
|
||||
if (i >= (int)lines.size()) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
push_value(L, i + 1);
|
||||
AssEntryToLua(L, lines[i]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int LuaAssFile::LuaParseKaraokeData(lua_State *L)
|
||||
{
|
||||
agi::scoped_ptr<AssEntry> e(LuaToAssEntry(L));
|
||||
|
@ -619,6 +641,7 @@ namespace Automation4 {
|
|||
set_field(L, "__newindex", closure_wrapper_v<&LuaAssFile::ObjectIndexWrite>);
|
||||
set_field(L, "__len", closure_wrapper<&LuaAssFile::ObjectGetLen>);
|
||||
set_field(L, "__gc", closure_wrapper_v<&LuaAssFile::ObjectGarbageCollect>);
|
||||
set_field(L, "__ipairs", closure_wrapper<&LuaAssFile::ObjectIPairs>);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
// register misc functions
|
||||
|
|
Loading…
Reference in a new issue