void lua_classvariable ( lua_State* luaVM, const char* szVariable, const char* set, const char* get ) { // Set lua_pushstring ( luaVM, "__set" ); lua_rawget ( luaVM, -2 ); CLuaCFunction* pSet = NULL; CLuaCFunction* pGet = NULL; if ( ( !set ) || ! ( pSet = CLuaCFunctions::GetFunction ( set ) ) ) { lua_pushstring ( luaVM, szVariable ); lua_pushstring ( luaVM, szVariable ); lua_pushcclosure ( luaVM, CLuaClassDefs::ReadOnly, 1 ); lua_rawset ( luaVM, -3 ); } else { lua_pushstring ( luaVM, szVariable ); lua_pushstring ( luaVM, szVariable ); lua_pushcclosure ( luaVM, pSet->GetAddress (), 1 ); lua_rawset ( luaVM, -3 ); } lua_pop ( luaVM, 1 ); // Get lua_pushstring ( luaVM, "__get" ); lua_rawget ( luaVM, -2 ); if ( ( !get ) || ! ( pGet = CLuaCFunctions::GetFunction ( get ) ) ) { lua_pushstring ( luaVM, szVariable ); lua_pushstring ( luaVM, szVariable ); lua_pushcclosure ( luaVM, CLuaClassDefs::WriteOnly, 1 ); lua_rawset ( luaVM, -3 ); } else { lua_pushstring ( luaVM, szVariable ); lua_pushstring ( luaVM, szVariable ); lua_pushcclosure ( luaVM, pGet->GetAddress (), 1 ); lua_rawset ( luaVM, -3 ); } lua_pop ( luaVM, 1 ); }
void lua_classfunction ( lua_State* luaVM, const char* szFunction, const char* fn ) { CLuaCFunction* pFunction = CLuaCFunctions::GetFunction ( fn ); if ( pFunction ) { lua_classfunction ( luaVM, szFunction, szFunction, pFunction->GetAddress () ); } else dassert ( false ); }
void lua_classfunction ( lua_State* luaVM, const char* szFunction, const char* szOriginal ) { CLuaCFunction* pFunction = CLuaCFunctions::GetFunction ( szOriginal ); if ( pFunction ) { lua_pushstring ( luaVM, "__class" ); lua_rawget ( luaVM, -2 ); lua_pushstring ( luaVM, szFunction ); lua_pushstring ( luaVM, szFunction ); lua_pushcclosure ( luaVM, pFunction->GetAddress (), 1 ); lua_rawset ( luaVM, -3 ); lua_pop ( luaVM, 1 ); } }