source: trunk/src/lua/lua_iterator.cc @ 540

Last change on this file since 540 was 538, checked in by epyon, 8 years ago
  • ECS rollback of usage of index_table
  • ECS prototype hashed_index_table
  • lua iterator interface
  • lua stack_proxy interface
  • table_guard iteration
File size: 1.0 KB
Line 
1// Copyright (C) 2017-2017 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
6
7#include "nv/lua/lua_iterator.hh"
8
9#include "nv/lua/lua_raw.hh"
10#include "nv/lua/lua_state.hh"
11
12using namespace nv;
13using namespace nv::lua;
14
15nv::lua::iterator_provider_base::iterator_provider_base( state* parent, int index )
16{
17        m_parent = parent;
18        m_index = nlua_absindex( *m_parent, index );
19        m_level = lua_gettop( *m_parent );
20        lua_pushnil( *m_parent );
21}
22
23nv::lua::iterator_provider_base::~iterator_provider_base()
24{
25        if ( m_parent )
26                lua_settop( *m_parent, m_level );
27}
28
29void nv::lua::iterator_base::next()
30{
31        if ( !m_state ) return;
32        lua_pop( *( m_state ), 1 );
33        if ( lua_next( *( m_state ), m_index ) == 0 )
34                m_state = nullptr;
35}
36
37nv::lua::iterator_base::iterator_base( state* state, sint32 index )
38        : m_state( state ), m_index( index )
39{
40        if ( m_state )
41                if ( lua_next( *( m_state ), m_index ) == 0 )
42                        m_state = nullptr;
43}
Note: See TracBrowser for help on using the repository browser.