Fix up more Lua error messages to be more meaningful (and work properly, in some cases)

This commit is contained in:
Monster Iestyn 2016-05-14 23:52:40 +01:00
parent 947e8c56ec
commit f579a12d2c
4 changed files with 18 additions and 6 deletions

View File

@ -497,7 +497,7 @@ static int libd_getColormap(lua_State *L)
{
skinnum = (INT32)luaL_checkinteger(L, 1);
if (skinnum < TC_ALLWHITE || skinnum >= MAXSKINS)
return luaL_error(L, "argument #1 is out of range");
return luaL_error(L, "skin number %d is out of range (%d - %d)", skinnum, TC_ALLWHITE, MAXSKINS-1);
}
else // skin name
{

View File

@ -188,7 +188,9 @@ static int lib_all7emeralds(lua_State *L)
// Returns both color and frame numbers!
static int lib_coloropposite(lua_State *L)
{
int colornum = ((int)luaL_checkinteger(L, 1)) % MAXSKINCOLORS;
UINT8 colornum = (UINT8)luaL_checkinteger(L, 1);
if (colornum >= MAXSKINCOLORS)
return luaL_error(L, "skincolor %d out of range (0 - %d).", colornum, MAXSKINCOLORS-1);
lua_pushinteger(L, Color_Opposite[colornum*2]); // push color
lua_pushinteger(L, Color_Opposite[colornum*2+1]); // push frame
return 2;

View File

@ -509,8 +509,13 @@ static int mobj_set(lua_State *L)
return luaL_error(L, "mobj.skin '%s' not found!", skin);
}
case mobj_color:
mo->color = ((UINT8)luaL_checkinteger(L, 3)) % MAXTRANSLATIONS;
{
UINT8 newcolor = (UINT8)luaL_checkinteger(L,3);
if (newcolor >= MAXTRANSLATIONS)
return luaL_error(L, "mobj.color %d out of range (0 - %d).", newcolor, MAXTRANSLATIONS-1);
mo->color = newcolor;
break;
}
case mobj_bnext:
return NOSETPOS;
case mobj_bprev:
@ -524,8 +529,8 @@ static int mobj_set(lua_State *L)
case mobj_type: // yeah sure, we'll let you change the mobj's type.
{
mobjtype_t newtype = luaL_checkinteger(L, 3);
if (newtype > MT_LASTFREESLOT)
return luaL_error(L, "mobj.type %u is out of bounds.", newtype);
if (newtype >= NUMMOBJTYPES)
return luaL_error(L, "mobj.type %d out of range (0 - %d).", newtype, NUMMOBJTYPES-1);
mo->type = newtype;
mo->info = &mobjinfo[newtype];
P_SetScale(mo, mo->scale);

View File

@ -389,7 +389,12 @@ static int player_set(lua_State *L)
else if (fastcmp(field,"flashpal"))
plr->flashpal = (UINT16)luaL_checkinteger(L, 3);
else if (fastcmp(field,"skincolor"))
plr->skincolor = ((UINT8)luaL_checkinteger(L, 3)) % MAXSKINCOLORS;
{
UINT8 newcolor = (UINT8)luaL_checkinteger(L,3);
if (newcolor >= MAXSKINCOLORS)
return luaL_error(L, "player.skincolor %d out of range (0 - %d).", newcolor, MAXSKINCOLORS-1);
plr->skincolor = newcolor;
}
else if (fastcmp(field,"score"))
plr->score = (UINT32)luaL_checkinteger(L, 3);
else if (fastcmp(field,"dashspeed"))