Show (short) list of possible enum values when an invalid value is encountered (resolves #1318)

All enum errors have (hopefully) been changed to a luax_enumerror, which has a
fixed error message. If additionally a list of valid options is passed, it
lists that in the error message. For every enum error with few options I've
implemented this using a getConstants call.

This solution has been designed specifically to reduce the number of template
instantiations (as I've been told that was a concern). All new template code
happens in places where there already was an instantiation of the relevant
StringMap. Of course there is still std::vector<std::string>...

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2017-10-02 17:11:53 +02:00
parent ac84589c57
commit 9e4374935d
72 changed files with 366 additions and 101 deletions
+4 -4
View File
@@ -51,7 +51,7 @@ int w_newSource(lua_State *L)
{
const char *stypestr = luaL_checkstring(L, 2);
if (stypestr && !Source::getConstant(stypestr, stype))
return luaL_error(L, "Invalid source type: %s", stypestr);
return luax_enumerror(L, "source type", Source::getConstants(stype), stypestr);
}
if (lua_isstring(L, 1) || luax_istype(L, 1, love::filesystem::File::type) || luax_istype(L, 1, love::filesystem::FileData::type))
@@ -297,7 +297,7 @@ int w_setDistanceModel(lua_State *L)
const char *modelStr = luaL_checkstring(L, 1);
Audio::DistanceModel distanceModel;
if (!Audio::getConstant(modelStr, distanceModel))
return luaL_error(L, "Invalid distance model: %s", modelStr);
return luax_enumerror(L, "distance model", Audio::getConstants(distanceModel), modelStr);
instance()->setDistanceModel(distanceModel);
return 0;
}
@@ -351,7 +351,7 @@ int w_setEffect(lua_State *L)
Effect::Type type = Effect::TYPE_MAX_ENUM;
const char *typestr = luaL_checkstring(L, -1);
if (!Effect::getConstant(typestr, type))
return luaL_error(L, "Invalid Effect type: %s", typestr);
return luax_enumerror(L, "effect type", Effect::getConstants(type), typestr);
lua_pop(L, 1);
std::map<Effect::Parameter, float> params;
@@ -386,7 +386,7 @@ int w_setEffect(lua_State *L)
paramstr = lua_tostring(L, -1);
Effect::Waveform waveform;
if (!Effect::getConstant(paramstr, waveform))
return luaL_error(L, "Invalid waveform type: %s", paramstr);
return luax_enumerror(L, "waveform type", paramstr);
params[param] = static_cast<int>(waveform);
break;
}