int CLuaFunctionDefs::GetKeyBoundToFunction ( lua_State* luaVM ) { SString strKey = "", strHitState = ""; CScriptArgReader argStream ( luaVM ); CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { if ( argStream.NextIsFunction ( ) ) { CLuaFunctionRef iLuaFunction = luaM_toref ( luaVM, 1 ); // get the key list < CScriptKeyBind* > ::const_iterator iter = m_pClientGame->GetScriptKeyBinds ()->IterBegin (); for ( ; iter != m_pClientGame->GetScriptKeyBinds ()->IterEnd (); iter++ ) { CScriptKeyBind* pScriptKeyBind = *iter; if ( !pScriptKeyBind->IsBeingDeleted () ) { switch ( pScriptKeyBind->GetType () ) { case SCRIPT_KEY_BIND_FUNCTION: { CScriptKeyFunctionBind* pBind = static_cast < CScriptKeyFunctionBind* > ( pScriptKeyBind ); // ACHTUNG: DOES IT FIND THE CORRECT LUA REF HERE? if ( iLuaFunction == pBind->m_iLuaFunction ) { lua_pushstring ( luaVM, pBind->boundKey->szKey ); return 1; } break; } case SCRIPT_KEY_BIND_CONTROL_FUNCTION: { CScriptControlFunctionBind* pBind = static_cast < CScriptControlFunctionBind* > ( pScriptKeyBind ); // ACHTUNG: DOES IT FIND THE CORRECT LUA REF HERE? if ( iLuaFunction == pBind->m_iLuaFunction ) { lua_pushstring ( luaVM, pBind->boundControl->szControl ); return 1; } break; } default: break; } } } lua_pushboolean ( luaVM, false ); return 1; } else m_pScriptDebugging->LogBadType ( luaVM ); } lua_pushboolean ( luaVM, false ); return 1; }
bool CScriptKeyBinds::ProcessKey ( const char* szKey, bool bHitState, eScriptKeyBindType bindType ) { m_bProcessingKey = true; SScriptBindableKey * pKey = NULL; SScriptBindableGTAControl * pControl = NULL; if ( bindType == SCRIPT_KEY_BIND_FUNCTION ) { pKey = GetBindableFromKey ( szKey ); if ( !pKey ) return false; } else if ( bindType == SCRIPT_KEY_BIND_CONTROL_FUNCTION ) { pControl = GetBindableFromControl ( szKey ); if ( !pControl ) return false; } bool bFound = false; CScriptKeyBind * pKeyBind = NULL; list < CScriptKeyBind* > cloneList = m_List; list < CScriptKeyBind* > ::iterator iter = cloneList.begin (); for ( ; iter != cloneList.end () ; ++iter ) { pKeyBind = *iter; if ( !pKeyBind->IsBeingDeleted () && pKeyBind->GetType () == bindType ) { switch ( bindType ) { case SCRIPT_KEY_BIND_FUNCTION: { CScriptKeyFunctionBind* pBind = static_cast < CScriptKeyFunctionBind* > ( pKeyBind ); if ( pBind->boundKey == pKey ) { if ( pBind->bHitState == bHitState ) { Call ( pBind ); bFound = true; } } break; } case SCRIPT_KEY_BIND_CONTROL_FUNCTION: { CScriptControlFunctionBind* pBind = static_cast < CScriptControlFunctionBind* > ( pKeyBind ); if ( pBind->boundControl == pControl ) { if ( pBind->bHitState == bHitState ) { Call ( pBind ); bFound = true; } } break; } } } } m_bProcessingKey = false; RemoveDeletedBinds (); return bFound; }
int CLuaFunctionDefs::GetFunctionsBoundToKey ( lua_State* luaVM ) { SString strKey = "", strHitState = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strKey ); argStream.ReadString ( strHitState, "" ); if ( !argStream.HasErrors ( ) ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { const char* szHitState = strHitState == "" ? NULL : strHitState.c_str(); bool bCheckHitState = false, bHitState = true; if ( szHitState ) { if ( stricmp ( szHitState, "down" ) == 0 ) bCheckHitState = true, bHitState = true; else if ( stricmp ( szHitState, "up" ) == 0 ) bCheckHitState = true, bHitState = false; } // Create a new table lua_newtable ( luaVM ); // Add all the bound functions to it unsigned int uiIndex = 0; list < CScriptKeyBind* > ::const_iterator iter = m_pClientGame->GetScriptKeyBinds ()->IterBegin (); for ( ; iter != m_pClientGame->GetScriptKeyBinds ()->IterEnd (); iter++ ) { CScriptKeyBind* pScriptKeyBind = *iter; if ( !pScriptKeyBind->IsBeingDeleted () ) { switch ( pScriptKeyBind->GetType () ) { case SCRIPT_KEY_BIND_FUNCTION: { CScriptKeyFunctionBind* pBind = static_cast < CScriptKeyFunctionBind* > ( pScriptKeyBind ); if ( !bCheckHitState || pBind->bHitState == bHitState ) { if ( strcmp ( strKey, pBind->boundKey->szKey ) == 0 ) { lua_pushnumber ( luaVM, ++uiIndex ); lua_rawgeti ( luaVM, LUA_REGISTRYINDEX, pBind->m_iLuaFunction.ToInt () ); lua_settable ( luaVM, -3 ); } } break; } case SCRIPT_KEY_BIND_CONTROL_FUNCTION: { CScriptControlFunctionBind* pBind = static_cast < CScriptControlFunctionBind* > ( pScriptKeyBind ); if ( !bCheckHitState || pBind->bHitState == bHitState ) { if ( strcmp ( strKey, pBind->boundControl->szControl ) == 0 ) { lua_pushnumber ( luaVM, ++uiIndex ); lua_rawgeti ( luaVM, LUA_REGISTRYINDEX, pBind->m_iLuaFunction.ToInt () ); lua_settable ( luaVM, -3 ); } } break; } default: break; } } } return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetFunctionsBoundToKey ( lua_State* luaVM ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { if ( lua_type ( luaVM, 1 ) == LUA_TSTRING ) { const char* szKey = lua_tostring ( luaVM, 1 ); const char* szHitState = NULL; if ( lua_type ( luaVM, 2 ) ) { szHitState = lua_tostring ( luaVM, 2 ); } bool bCheckHitState = false, bHitState = true; if ( szHitState ) { if ( stricmp ( szHitState, "down" ) == 0 ) bCheckHitState = true, bHitState = true; else if ( stricmp ( szHitState, "up" ) == 0 ) bCheckHitState = true, bHitState = false; } // Create a new table lua_newtable ( luaVM ); // Add all the bound functions to it unsigned int uiIndex = 0; list < CScriptKeyBind* > ::const_iterator iter = m_pClientGame->GetScriptKeyBinds ()->IterBegin (); for ( ; iter != m_pClientGame->GetScriptKeyBinds ()->IterEnd (); iter++ ) { CScriptKeyBind* pScriptKeyBind = *iter; if ( !pScriptKeyBind->IsBeingDeleted () ) { switch ( pScriptKeyBind->GetType () ) { case SCRIPT_KEY_BIND_FUNCTION: { CScriptKeyFunctionBind* pBind = static_cast < CScriptKeyFunctionBind* > ( pScriptKeyBind ); if ( !bCheckHitState || pBind->bHitState == bHitState ) { if ( strcmp ( szKey, pBind->boundKey->szKey ) == 0 ) { lua_pushnumber ( luaVM, ++uiIndex ); lua_rawgeti ( luaVM, LUA_REGISTRYINDEX, pBind->m_iLuaFunction ); lua_settable ( luaVM, -3 ); } } break; } case SCRIPT_KEY_BIND_CONTROL_FUNCTION: { CScriptControlFunctionBind* pBind = static_cast < CScriptControlFunctionBind* > ( pScriptKeyBind ); if ( !bCheckHitState || pBind->bHitState == bHitState ) { if ( strcmp ( szKey, pBind->boundControl->szControl ) == 0 ) { lua_pushnumber ( luaVM, ++uiIndex ); lua_rawgeti ( luaVM, LUA_REGISTRYINDEX, pBind->m_iLuaFunction ); lua_settable ( luaVM, -3 ); } } break; } default: break; } } } return 1; } else m_pScriptDebugging->LogBadType ( luaVM, "getFunctionsBoundToKey" ); } lua_pushboolean ( luaVM, false ); return 1; }