Skip to content

Commit

Permalink
Change raiseEvent to allow nil arguments and return an error when pas…
Browse files Browse the repository at this point in the history
…sed arguments of unhandled types.
  • Loading branch information
eewallace committed Jan 21, 2016
1 parent 2836052 commit a087649
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/TEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define ARGUMENT_TYPE_NUMBER 0
#define ARGUMENT_TYPE_STRING 1
#define ARGUMENT_TYPE_BOOLEAN 2
#define ARGUMENT_TYPE_NIL 3

class TEvent
{
Expand Down
15 changes: 15 additions & 0 deletions src/TLuaInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ int TLuaInterpreter::raiseEvent( lua_State * L )
pE.mArgumentList.append( QString::number(lua_toboolean( L, i )) );
pE.mArgumentTypeList.append( ARGUMENT_TYPE_BOOLEAN );
}
else if( lua_isnil( L, i ) )
{
pE.mArgumentList.append( QString() );
pE.mArgumentTypeList.append( ARGUMENT_TYPE_NIL );
}
else
{
lua_pushstring( L, "raiseEvent: invalid argument type" );
lua_error( L );
return 1;
}
}
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
pHost->raiseEvent( pE );
Expand Down Expand Up @@ -11915,6 +11926,10 @@ bool TLuaInterpreter::callEventHandler(const QString & function, const TEvent &
{
lua_pushboolean( L, pE.mArgumentList[i].toInt() );
}
else if( pE.mArgumentTypeList[i] == ARGUMENT_TYPE_NIL )
{
lua_pushnil( L );
}
else
{
lua_pushstring( L, pE.mArgumentList[i].toLatin1().data() );
Expand Down

0 comments on commit a087649

Please sign in to comment.