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
@@ -291,7 +291,7 @@ int w_Mesh_getVertexFormat(lua_State *L)
for (size_t i = 0; i < vertexformat.size(); i++)
{
if (!Mesh::getConstant(vertexformat[i].type, tname))
return luaL_error(L, "Unknown vertex attribute data type.");
return luax_enumerror(L, "vertex attribute data type", Mesh::getConstants(vertexformat[i].type), tname);
lua_createtable(L, 3, 0);
@@ -339,7 +339,7 @@ int w_Mesh_attachAttribute(lua_State *L)
Mesh::AttributeStep step = Mesh::STEP_PER_VERTEX;
const char *stepstr = lua_isnoneornil(L, 4) ? nullptr : luaL_checkstring(L, 4);
if (stepstr != nullptr && !Mesh::getConstant(stepstr, step))
return luaL_error(L, "Invalid vertex attribute step: %s", stepstr);
return luax_enumerror(L, "vertex attribute step", Mesh::getConstants(step), stepstr);
const char *attachname = luaL_optstring(L, 5, name);
@@ -382,7 +382,7 @@ int w_Mesh_setVertexMap(lua_State *L)
const char *indextypestr = luaL_checkstring(L, 3);
IndexDataType indextype;
if (!vertex::getConstant(indextypestr, indextype))
return luaL_error(L, "Invalid index data type: %s", indextypestr);
return luax_enumerror(L, "index data type", vertex::getConstants(indextype), indextypestr);
size_t datatypesize = vertex::getIndexDataSize(indextype);
@@ -488,7 +488,7 @@ int w_Mesh_setDrawMode(lua_State *L)
Mesh::DrawMode mode;
if (!Mesh::getConstant(str, mode))
return luaL_error(L, "Invalid mesh draw mode: %s", str);
return luax_enumerror(L, "mesh draw mode", Mesh::getConstants(mode), str);
t->setDrawMode(mode);
return 0;