Changeset 163


Ignore:
Timestamp:
07/15/13 23:43:00 (12 years ago)
Author:
epyon
Message:
  • lua_state - lua::state::register_enum added (based on type database)
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/lua/lua_state.hh

    r162 r163  
    8989                        reference register_object( object * o );
    9090                        void unregister_object( object * o );
     91                        void register_enum( type_database* db, const std::string& name, const std::string& prefix = std::string() );
    9192                        operator lua_State*() { return L; }
    9293                        ~state();
  • trunk/src/lua/lua_state.cc

    r162 r163  
    372372        }
    373373}
     374
     375void lua::state::register_enum( type_database* db, const std::string& name, const std::string& prefix /*= std::string() */ )
     376{
     377        type_entry* et = db->get_type( name );
     378
     379        for ( const auto& entry : et->enum_list )
     380        {
     381                lua_pushinteger( L, entry.value );
     382                if ( prefix.empty() )
     383                {
     384                        lua_setglobal( L, entry.name.c_str() );
     385                }
     386                else
     387                {
     388                        lua_setglobal( L, ( prefix + entry.name ).c_str() );
     389                }
     390        }
     391}
Note: See TracChangeset for help on using the changeset viewer.