mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
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:
@@ -111,7 +111,7 @@ int w_Source_seek(lua_State *L)
|
||||
Source::Unit u = Source::UNIT_SECONDS;
|
||||
const char *unit = lua_isnoneornil(L, 3) ? 0 : lua_tostring(L, 3);
|
||||
if (unit && !t->getConstant(unit, u))
|
||||
return luaL_error(L, "Invalid Source time unit: %s", unit);
|
||||
return luax_enumerror(L, "time unit", Source::getConstants(u), unit);
|
||||
|
||||
t->seek(offset, u);
|
||||
return 0;
|
||||
@@ -124,7 +124,7 @@ int w_Source_tell(lua_State *L)
|
||||
Source::Unit u = Source::UNIT_SECONDS;
|
||||
const char *unit = lua_isnoneornil(L, 2) ? 0 : lua_tostring(L, 2);
|
||||
if (unit && !t->getConstant(unit, u))
|
||||
return luaL_error(L, "Invalid Source time unit: %s", unit);
|
||||
return luax_enumerror(L, "time unit", Source::getConstants(u), unit);
|
||||
|
||||
lua_pushnumber(L, t->tell(u));
|
||||
return 1;
|
||||
@@ -137,7 +137,7 @@ int w_Source_getDuration(lua_State *L)
|
||||
Source::Unit u = Source::UNIT_SECONDS;
|
||||
const char *unit = lua_isnoneornil(L, 2) ? 0 : lua_tostring(L, 2);
|
||||
if (unit && !t->getConstant(unit, u))
|
||||
return luaL_error(L, "Invalid Source time unit: %s", unit);
|
||||
return luax_enumerror(L, "time unit", Source::getConstants(u), unit);
|
||||
|
||||
lua_pushnumber(L, t->getDuration(u));
|
||||
return 1;
|
||||
@@ -363,7 +363,7 @@ int setFilterReadFilter(lua_State *L, int idx, std::map<Filter::Parameter, float
|
||||
Filter::Type type = Filter::TYPE_MAX_ENUM;
|
||||
const char *typestr = luaL_checkstring(L, -1);
|
||||
if (!Filter::getConstant(typestr, type))
|
||||
return luaL_error(L, "Invalid Filter type: %s", typestr);
|
||||
return luax_enumerror(L, "filter type", Filter::getConstants(type), typestr);
|
||||
|
||||
lua_pop(L, 1);
|
||||
params[Filter::FILTER_TYPE] = static_cast<int>(type);
|
||||
|
||||
Reference in New Issue
Block a user