Changeset 212 for trunk/src


Ignore:
Timestamp:
09/09/13 19:29:23 (12 years ago)
Author:
epyon
Message:
  • lua/dispatch - powerful module for binding any function or method to lua
  • lua/state - added initial method/function registration
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lua/lua_state.cc

    r209 r212  
    251251}
    252252
     253
     254void lua::state_wrapper::register_native_function( lfunction f, const char* name )
     255{
     256        if ( m_global ) push_global_table();
     257        lua_pushcfunction( m_state, f );
     258        lua_setfield( m_state, -2, name );
     259        if ( m_global ) pop_global_table();
     260}
     261
    253262void lua::state::log_stack()
    254263{
     
    287296        if ( t == nullptr ) return ref_none;
    288297        return register_object( o, t->name.c_str() );
     298}
     299
     300void lua::state::register_native_object_method( const char* lua_name, const char* name, lfunction f )
     301{
     302        stack_guard guard( this );
     303        lua_getglobal( m_state, lua_name );
     304        if ( lua_isnil( m_state, -1 ) )
     305        {
     306                NV_THROW( runtime_error, std::string( lua_name ) + " type not registered!" );
     307        }
     308        lua_pushcfunction( m_state, f );
     309        lua_setfield( m_state, -2, name );
    289310}
    290311
     
    411432        lua_settop( m_state, m_level );
    412433}
     434
     435int nv::lua::upvalue_index( int i )
     436{
     437        return lua_upvalueindex(i);
     438}
Note: See TracChangeset for help on using the changeset viewer.