Skip to content

Commit

Permalink
Fix GetCommandsBoundToKey to handle bound keys without szArguments (#40)
Browse files Browse the repository at this point in the history
In cases where szArguments is empty, the return table will be empty,
even when there is a command bound to that key
  • Loading branch information
Necktrox authored and qaisjp committed Jul 23, 2016
1 parent 5373bde commit 0087420
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,12 @@ int CLuaFunctionDefs::GetCommandsBoundToKey ( lua_State* luaVM )
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 )
Expand All @@ -620,25 +621,28 @@ int CLuaFunctionDefs::GetCommandsBoundToKey ( lua_State* luaVM )
lua_newtable ( luaVM );

// Add all the bound commands to it
unsigned int uiIndex = 0;
list < CKeyBind* > ::const_iterator iter = g_pCore->GetKeyBinds ()->IterBegin ();

for ( ; iter != g_pCore->GetKeyBinds ()->IterEnd (); iter++ )
{
CKeyBind* pKeyBind = *iter;

if ( !pKeyBind->IsBeingDeleted () && pKeyBind->bActive && pKeyBind->GetType () == KEY_BIND_COMMAND )
{
CCommandBind* pBind = static_cast < CCommandBind* > ( pKeyBind );
if ( !bCheckHitState || pBind->bHitState == bHitState )
CCommandBind* pCommandBind = static_cast < CCommandBind* > ( pKeyBind );

if ( !bCheckHitState || pCommandBind->bHitState == bHitState )
{
if ( strcmp ( strKey, pBind->boundKey->szKey ) == 0 )
if ( strcmp ( strKey, pCommandBind->boundKey->szKey ) == 0 )
{
lua_pushstring ( luaVM, pBind->szCommand );
lua_pushstring ( luaVM, pBind->szArguments );
lua_pushstring ( luaVM, pCommandBind->szCommand );
lua_pushstring ( luaVM, ( pCommandBind->szArguments && pCommandBind->szArguments[0] != '\0' ) ? pCommandBind->szArguments : "" );
lua_settable ( luaVM, -3 );
}
}
}
}

return 1;
}
}
Expand Down

0 comments on commit 0087420

Please sign in to comment.