Changeset 212
- Timestamp:
- 09/09/13 19:29:23 (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/lua/lua_state.hh
r209 r212 12 12 #include <nv/common.hh> 13 13 #include <nv/flags.hh> 14 14 15 #include <nv/lua/lua_path.hh> 15 16 #include <nv/lua/lua_values.hh> 17 #include <nv/lua/lua_dispatch.hh> 16 18 #include <string> 17 18 struct lua_State;19 19 20 20 namespace nv … … 26 26 const int ret_multi = -1; 27 27 28 class state; 28 int upvalue_index( int i ); 29 29 30 typedef int reference; 30 31 … … 131 132 132 133 bool is_defined( const path& p ) { return is_defined( p, m_global ); } 134 void register_native_function( lfunction f, const char* name ); 135 template < typename F, F* f > 136 void register_function( const char* name ) 137 { 138 register_native_function( detail::function_wrapper< F, f >, name ); 139 } 133 140 protected: 134 141 bool is_defined( const path& p, bool global ); … … 178 185 void store_metadata( object* o, const std::string& metaname, void* pointer ); 179 186 void unregister_object( object * o ); 187 void register_native_object_method( const char* lua_name, const char* name, lfunction f ); 188 template < typename F, F* f > 189 void register_object_method( const char* lua_name, const char* name ) 190 { 191 register_native_object_method( lua_name, name, detail::object_method_wrapper< typename memfn_class_type<F>, F, f > ); 192 } 180 193 void register_enum( type_database* db, const std::string& name, const std::string& prefix = std::string() ); 181 194 operator lua_State*() { return m_state; } -
trunk/src/lua/lua_state.cc
r209 r212 251 251 } 252 252 253 254 void 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 253 262 void lua::state::log_stack() 254 263 { … … 287 296 if ( t == nullptr ) return ref_none; 288 297 return register_object( o, t->name.c_str() ); 298 } 299 300 void 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 ); 289 310 } 290 311 … … 411 432 lua_settop( m_state, m_level ); 412 433 } 434 435 int nv::lua::upvalue_index( int i ) 436 { 437 return lua_upvalueindex(i); 438 }
Note: See TracChangeset
for help on using the changeset viewer.