Skip to content

Commit

Permalink
proper IPairs iterator implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
4z0t committed Nov 30, 2024
1 parent 60fda9c commit 2b77e2e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 15 deletions.
1 change: 0 additions & 1 deletion include/LuaAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ class LuaObject { // 0x14 bytes
int GetInteger() const asm("0x907910");
int GetN() const asm("0x907e50");
int GetTableCount() asm("0x90a410");
int IsPassed() asm("0x907440");
lua_State *GetActiveCState() const asm("0x9072c0");
void AssignBoolean(LuaState *state, bool value) asm("0x909600");
void AssignInteger(LuaState *state, int value) asm("0x909650");
Expand Down
9 changes: 2 additions & 7 deletions section/Lua/Iterators/IPairs.cxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "IPairs.h"

IPairsEndIterator::IPairsEndIterator(const LuaObject &table)
: n{table.GetN()} {}

int IPairsEndIterator::GetN() const { return n; }

IPairsIterator::IPairsIterator(const LuaObject &table)
: table{table}, index{0}, value{table.m_state} {}

Expand All @@ -22,12 +17,12 @@ const std::pair<int, LuaObject> IPairsIterator::operator*() const {
std::pair<int, LuaObject> IPairsIterator::operator*() { return {index, value}; }

bool IPairsIterator::operator!=(const IPairsEndIterator &end_it) const {
return index <= end_it.GetN();
return !value.IsNil();
}

IPairs::IPairs(const LuaObject &table) : table{table} {
luaplus_assert(table.IsTable());
}

IPairsIterator IPairs::begin() { return ++IPairsIterator(table); }
IPairsEndIterator IPairs::end() { return IPairsEndIterator{table}; }
IPairsEndIterator IPairs::end() { return IPairsEndIterator{}; }
7 changes: 0 additions & 7 deletions section/Lua/Iterators/IPairs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
#include <utility>

class IPairsEndIterator {
public:
IPairsEndIterator(const LuaObject &table);

int GetN() const;

private:
int n;
};

class IPairsIterator {
Expand Down

0 comments on commit 2b77e2e

Please sign in to comment.