patch: better errors for createMapLabel

Post Reply
User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

patch: better errors for createMapLabel

Post by Vadi »

It was frustrating experience trying to find out which one of the 10 arguments to createMapLabel were wrong, so here's a patch that rectifies this:

[cpp]
int TLuaInterpreter::createMapLabel( lua_State * L )
{
int area, fgr, fgg, fgb, bgr, bgg, bgb;
float posx, posy;
string text;
if( ! lua_isnumber( L, 1 ) )
{
lua_pushstring( L, "createMapLabel: missing the area ID" );
lua_error( L );
return 1;
}
else
{
area = lua_tointeger( L, 1 );
}

if( ! lua_isstring( L, 2 ) )
{
lua_pushstring( L, "createMapLabel: missing the text" );
lua_error( L );
return 1;
}
else
{
text = lua_tostring( L, 2 );
}

if( ! lua_isnumber( L, 3 ) )
{
lua_pushstring( L, "createMapLabel: missing x coordinate" );
lua_error( L );
return 1;
}
else
{
posx = lua_tonumber( L, 3 );
}

if( ! lua_isnumber( L, 4 ) )
{
lua_pushstring( L, "createMapLabel: missing the y coordinate" );
lua_error( L );
return 1;
}
else
{
posy = lua_tonumber( L, 4 );
}

if( ! lua_isnumber( L, 5 ) )
{
lua_pushstring( L, "createMapLabel: missing foreground red number" );
lua_error( L );
return 1;
}
else
{
fgr = lua_tointeger( L, 5 );
}

if( ! lua_isnumber( L, 6 ) )
{
lua_pushstring( L, "createMapLabel: missing foreground green number" );
lua_error( L );
return 1;
}
else
{
fgg = lua_tointeger( L, 6 );
}

if( ! lua_isnumber( L, 7 ) )
{
lua_pushstring( L, "createMapLabel: missing foreground blue number" );
lua_error( L );
return 1;
}
else
{
fgb = lua_tointeger( L, 7 );
}

if( ! lua_isnumber( L, 8 ) )
{
lua_pushstring( L, "createMapLabel: missing background red number" );
lua_error( L );
return 1;
}
else
{
bgr = lua_tointeger( L, 8 );
}

if( ! lua_isnumber( L, 9 ) )
{
lua_pushstring( L, "createMapLabel: missing background green number" );
lua_error( L );
return 1;
}
else
{
bgg = lua_tointeger( L, 9 );
}

if( ! lua_isnumber( L, 10 ) )
{
lua_pushstring( L, "createMapLabel: missing background blue number" );
lua_error( L );
return 1;
}
else
{
bgb = lua_tointeger( L, 10 );
}

QString _text = text.c_str();
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
QColor fg = QColor(fgr,fgg,fgb);
QColor bg = QColor(bgr, bgg, bgb);
lua_pushinteger( L, pHost->mpMap->createMapLabel( area, _text, posx, posy, fg, bg ) );
return 1;
}
[/cpp]

Post Reply