mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +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:
@@ -190,6 +190,11 @@ bool Canvas::getConstant(MipmapMode in, const char *&out)
|
||||
return mipmapModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Canvas::getConstants(MipmapMode)
|
||||
{
|
||||
return mipmapModes.getNames();
|
||||
}
|
||||
|
||||
StringMap<Canvas::MipmapMode, Canvas::MIPMAPS_MAX_ENUM>::Entry Canvas::mipmapEntries[] =
|
||||
{
|
||||
{ "none", MIPMAPS_NONE },
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
|
||||
static bool getConstant(const char *in, MipmapMode &out);
|
||||
static bool getConstant(MipmapMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(MipmapMode);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -1012,6 +1012,11 @@ bool Font::getConstant(AlignMode in, const char *&out)
|
||||
return alignModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Font::getConstants(AlignMode)
|
||||
{
|
||||
return alignModes.getNames();
|
||||
}
|
||||
|
||||
StringMap<Font::AlignMode, Font::ALIGN_MAX_ENUM>::Entry Font::alignModeEntries[] =
|
||||
{
|
||||
{ "left", ALIGN_LEFT },
|
||||
|
||||
@@ -181,6 +181,7 @@ public:
|
||||
|
||||
static bool getConstant(const char *in, AlignMode &out);
|
||||
static bool getConstant(AlignMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(AlignMode);
|
||||
|
||||
static int fontCount;
|
||||
|
||||
|
||||
@@ -1444,6 +1444,11 @@ bool Graphics::getConstant(DrawMode in, const char *&out)
|
||||
return drawModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Graphics::getConstants(DrawMode)
|
||||
{
|
||||
return drawModes.getNames();
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, ArcMode &out)
|
||||
{
|
||||
return arcModes.find(in, out);
|
||||
@@ -1454,6 +1459,11 @@ bool Graphics::getConstant(ArcMode in, const char *&out)
|
||||
return arcModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Graphics::getConstants(ArcMode)
|
||||
{
|
||||
return arcModes.getNames();
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, BlendMode &out)
|
||||
{
|
||||
return blendModes.find(in, out);
|
||||
@@ -1464,6 +1474,11 @@ bool Graphics::getConstant(BlendMode in, const char *&out)
|
||||
return blendModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Graphics::getConstants(BlendMode)
|
||||
{
|
||||
return blendModes.getNames();
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, BlendAlpha &out)
|
||||
{
|
||||
return blendAlphaModes.find(in, out);
|
||||
@@ -1474,6 +1489,11 @@ bool Graphics::getConstant(BlendAlpha in, const char *&out)
|
||||
return blendAlphaModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Graphics::getConstants(BlendAlpha)
|
||||
{
|
||||
return blendAlphaModes.getNames();
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, LineStyle &out)
|
||||
{
|
||||
return lineStyles.find(in, out);
|
||||
@@ -1484,6 +1504,11 @@ bool Graphics::getConstant(LineStyle in, const char *&out)
|
||||
return lineStyles.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Graphics::getConstants(LineStyle)
|
||||
{
|
||||
return lineStyles.getNames();
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, LineJoin &out)
|
||||
{
|
||||
return lineJoins.find(in, out);
|
||||
@@ -1494,6 +1519,11 @@ bool Graphics::getConstant(LineJoin in, const char *&out)
|
||||
return lineJoins.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Graphics::getConstants(LineJoin)
|
||||
{
|
||||
return lineJoins.getNames();
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, Feature &out)
|
||||
{
|
||||
return features.find(in, out);
|
||||
@@ -1524,6 +1554,11 @@ bool Graphics::getConstant(StackType in, const char *&out)
|
||||
return stackTypes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Graphics::getConstants(StackType)
|
||||
{
|
||||
return stackTypes.getNames();
|
||||
}
|
||||
|
||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
|
||||
{
|
||||
{ "line", DRAW_LINE },
|
||||
|
||||
@@ -773,21 +773,27 @@ public:
|
||||
|
||||
static bool getConstant(const char *in, DrawMode &out);
|
||||
static bool getConstant(DrawMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(DrawMode);
|
||||
|
||||
static bool getConstant(const char *in, ArcMode &out);
|
||||
static bool getConstant(ArcMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(ArcMode);
|
||||
|
||||
static bool getConstant(const char *in, BlendMode &out);
|
||||
static bool getConstant(BlendMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(BlendMode);
|
||||
|
||||
static bool getConstant(const char *in, BlendAlpha &out);
|
||||
static bool getConstant(BlendAlpha in, const char *&out);
|
||||
static std::vector<std::string> getConstants(BlendAlpha);
|
||||
|
||||
static bool getConstant(const char *in, LineStyle &out);
|
||||
static bool getConstant(LineStyle in, const char *&out);
|
||||
static std::vector<std::string> getConstants(LineStyle);
|
||||
|
||||
static bool getConstant(const char *in, LineJoin &out);
|
||||
static bool getConstant(LineJoin in, const char *&out);
|
||||
static std::vector<std::string> getConstants(LineJoin);
|
||||
|
||||
static bool getConstant(const char *in, Feature &out);
|
||||
static bool getConstant(Feature in, const char *&out);
|
||||
@@ -797,6 +803,7 @@ public:
|
||||
|
||||
static bool getConstant(const char *in, StackType &out);
|
||||
static bool getConstant(StackType in, const char *&out);
|
||||
static std::vector<std::string> getConstants(StackType);
|
||||
|
||||
// Default shader code (a shader is always required internally.)
|
||||
static Shader::ShaderSource defaultShaderCode[Shader::STANDARD_MAX_ENUM][Shader::LANGUAGE_MAX_ENUM][2];
|
||||
|
||||
@@ -659,16 +659,21 @@ size_t Mesh::getAttribFormatSize(const AttribFormat &format)
|
||||
}
|
||||
}
|
||||
|
||||
bool Mesh::getConstant(const char *in, Mesh::DrawMode &out)
|
||||
bool Mesh::getConstant(const char *in, DrawMode &out)
|
||||
{
|
||||
return drawModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Mesh::getConstant(Mesh::DrawMode in, const char *&out)
|
||||
bool Mesh::getConstant(DrawMode in, const char *&out)
|
||||
{
|
||||
return drawModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Mesh::getConstants(DrawMode)
|
||||
{
|
||||
return drawModes.getNames();
|
||||
}
|
||||
|
||||
bool Mesh::getConstant(const char *in, DataType &out)
|
||||
{
|
||||
return dataTypes.find(in, out);
|
||||
@@ -679,6 +684,11 @@ bool Mesh::getConstant(DataType in, const char *&out)
|
||||
return dataTypes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Mesh::getConstants(DataType)
|
||||
{
|
||||
return dataTypes.getNames();
|
||||
}
|
||||
|
||||
bool Mesh::getConstant(const char *in, AttributeStep &out)
|
||||
{
|
||||
return attributeSteps.find(in, out);
|
||||
@@ -689,6 +699,11 @@ bool Mesh::getConstant(AttributeStep in, const char *&out)
|
||||
return attributeSteps.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Mesh::getConstants(AttributeStep)
|
||||
{
|
||||
return attributeSteps.getNames();
|
||||
}
|
||||
|
||||
StringMap<Mesh::DrawMode, Mesh::DRAWMODE_MAX_ENUM>::Entry Mesh::drawModeEntries[] =
|
||||
{
|
||||
{ "fan", DRAWMODE_FAN },
|
||||
|
||||
@@ -202,12 +202,15 @@ public:
|
||||
|
||||
static bool getConstant(const char *in, DrawMode &out);
|
||||
static bool getConstant(DrawMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(DrawMode);
|
||||
|
||||
static bool getConstant(const char *in, DataType &out);
|
||||
static bool getConstant(DataType in, const char *&out);
|
||||
static std::vector<std::string> getConstants(DataType);
|
||||
|
||||
static bool getConstant(const char *in, AttributeStep &out);
|
||||
static bool getConstant(AttributeStep in, const char *&out);
|
||||
static std::vector<std::string> getConstants(AttributeStep);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -1103,6 +1103,11 @@ bool ParticleSystem::getConstant(AreaSpreadDistribution in, const char *&out)
|
||||
return distributions.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> ParticleSystem::getConstants(AreaSpreadDistribution)
|
||||
{
|
||||
return distributions.getNames();
|
||||
}
|
||||
|
||||
bool ParticleSystem::getConstant(const char *in, InsertMode &out)
|
||||
{
|
||||
return insertModes.find(in, out);
|
||||
@@ -1113,6 +1118,11 @@ bool ParticleSystem::getConstant(InsertMode in, const char *&out)
|
||||
return insertModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> ParticleSystem::getConstants(InsertMode)
|
||||
{
|
||||
return insertModes.getNames();
|
||||
}
|
||||
|
||||
StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM>::Entry ParticleSystem::distributionsEntries[] =
|
||||
{
|
||||
{ "none", DISTRIBUTION_NONE },
|
||||
|
||||
@@ -541,9 +541,11 @@ public:
|
||||
|
||||
static bool getConstant(const char *in, AreaSpreadDistribution &out);
|
||||
static bool getConstant(AreaSpreadDistribution in, const char *&out);
|
||||
static std::vector<std::string> getConstants(AreaSpreadDistribution);
|
||||
|
||||
static bool getConstant(const char *in, InsertMode &out);
|
||||
static bool getConstant(InsertMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(InsertMode);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -384,6 +384,11 @@ bool Texture::getConstant(TextureType in, const char *&out)
|
||||
return texTypes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Texture::getConstants(TextureType)
|
||||
{
|
||||
return texTypes.getNames();
|
||||
}
|
||||
|
||||
bool Texture::getConstant(const char *in, FilterMode &out)
|
||||
{
|
||||
return filterModes.find(in, out);
|
||||
@@ -394,6 +399,11 @@ bool Texture::getConstant(FilterMode in, const char *&out)
|
||||
return filterModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Texture::getConstants(FilterMode)
|
||||
{
|
||||
return filterModes.getNames();
|
||||
}
|
||||
|
||||
bool Texture::getConstant(const char *in, WrapMode &out)
|
||||
{
|
||||
return wrapModes.find(in, out);
|
||||
@@ -404,6 +414,11 @@ bool Texture::getConstant(WrapMode in, const char *&out)
|
||||
return wrapModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> Texture::getConstants(WrapMode)
|
||||
{
|
||||
return wrapModes.getNames();
|
||||
}
|
||||
|
||||
StringMap<TextureType, TEXTURE_MAX_ENUM>::Entry Texture::texTypeEntries[] =
|
||||
{
|
||||
{ "2d", TEXTURE_2D },
|
||||
|
||||
@@ -162,12 +162,15 @@ public:
|
||||
|
||||
static bool getConstant(const char *in, TextureType &out);
|
||||
static bool getConstant(TextureType in, const char *&out);
|
||||
static std::vector<std::string> getConstants(TextureType);
|
||||
|
||||
static bool getConstant(const char *in, FilterMode &out);
|
||||
static bool getConstant(FilterMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(FilterMode);
|
||||
|
||||
static bool getConstant(const char *in, WrapMode &out);
|
||||
static bool getConstant(WrapMode in, const char *&out);
|
||||
static std::vector<std::string> getConstants(WrapMode);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -85,6 +85,11 @@ bool getConstant(StencilAction in, const char *&out)
|
||||
return stencilActions.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(StencilAction)
|
||||
{
|
||||
return stencilActions.getNames();
|
||||
}
|
||||
|
||||
bool getConstant(const char *in, CompareMode &out)
|
||||
{
|
||||
return compareModes.find(in, out);
|
||||
@@ -95,5 +100,10 @@ bool getConstant(CompareMode in, const char *&out)
|
||||
return compareModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(CompareMode)
|
||||
{
|
||||
return compareModes.getNames();
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
@@ -60,9 +63,11 @@ CompareMode getReversedCompareMode(CompareMode mode);
|
||||
|
||||
bool getConstant(const char *in, StencilAction &out);
|
||||
bool getConstant(StencilAction in, const char *&out);
|
||||
std::vector<std::string> getConstants(StencilAction);
|
||||
|
||||
bool getConstant(const char *in, CompareMode &out);
|
||||
bool getConstant(CompareMode in, const char *&out);
|
||||
std::vector<std::string> getConstants(CompareMode);
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -254,6 +254,11 @@ bool getConstant(IndexDataType in, const char *&out)
|
||||
return indexTypes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(IndexDataType)
|
||||
{
|
||||
return indexTypes.getNames();
|
||||
}
|
||||
|
||||
bool getConstant(const char *in, Usage &out)
|
||||
{
|
||||
return usages.find(in, out);
|
||||
@@ -264,6 +269,11 @@ bool getConstant(Usage in, const char *&out)
|
||||
return usages.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(Usage)
|
||||
{
|
||||
return usages.getNames();
|
||||
}
|
||||
|
||||
} // vertex
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
// C
|
||||
#include <stddef.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -176,9 +178,11 @@ bool getConstant(VertexAttribID in, const char *&out);
|
||||
|
||||
bool getConstant(const char *in, IndexDataType &out);
|
||||
bool getConstant(IndexDataType in, const char *&out);
|
||||
std::vector<std::string> getConstants(IndexDataType);
|
||||
|
||||
bool getConstant(const char *in, Usage &out);
|
||||
bool getConstant(Usage in, const char *&out);
|
||||
std::vector<std::string> getConstants(Usage);
|
||||
|
||||
} // vertex
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ int w_Canvas_getMipmapMode(lua_State *L)
|
||||
Canvas *c = luax_checkcanvas(L, 1);
|
||||
const char *str;
|
||||
if (!Canvas::getConstant(c->getMipmapMode(), str))
|
||||
return luaL_error(L, "Unknown mipmap mode.");
|
||||
return luax_enumerror(L, "mipmap mode", Canvas::getConstants(Canvas::MIPMAPS_MAX_ENUM), str);
|
||||
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
|
||||
@@ -145,9 +145,9 @@ int w_Font_setFilter(lua_State *L)
|
||||
const char *magstr = luaL_optstring(L, 3, minstr);
|
||||
|
||||
if (!Texture::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.min), minstr);
|
||||
if (!Texture::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.mag), magstr);
|
||||
|
||||
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
|
||||
|
||||
|
||||
@@ -519,7 +519,7 @@ int w_captureScreenshot(lua_State *L)
|
||||
|
||||
image::FormatHandler::EncodedFormat format;
|
||||
if (!image::ImageData::getConstant(ext.c_str(), format))
|
||||
return luaL_error(L, "Invalid encoded image format: %s", ext.c_str());
|
||||
return luax_enumerror(L, "encoded image format", image::ImageData::getConstants(format), ext.c_str());
|
||||
|
||||
ScreenshotFileInfo *fileinfo = new ScreenshotFileInfo;
|
||||
fileinfo->filename = filename;
|
||||
@@ -609,7 +609,7 @@ int w_stencil(lua_State *L)
|
||||
{
|
||||
const char *actionstr = luaL_checkstring(L, 2);
|
||||
if (!getConstant(actionstr, action))
|
||||
return luaL_error(L, "Invalid stencil draw action: %s", actionstr);
|
||||
return luax_enumerror(L, "stencil draw action", getConstants(action), actionstr);
|
||||
}
|
||||
|
||||
int stencilvalue = (int) luaL_optinteger(L, 3, 1);
|
||||
@@ -647,7 +647,7 @@ int w_setStencilTest(lua_State *L)
|
||||
{
|
||||
const char *comparestr = luaL_checkstring(L, 1);
|
||||
if (!getConstant(comparestr, compare))
|
||||
return luaL_error(L, "Invalid compare mode: %s", comparestr);
|
||||
return luax_enumerror(L, "compare mode", getConstants(compare), comparestr);
|
||||
|
||||
comparevalue = (int) luaL_checkinteger(L, 2);
|
||||
}
|
||||
@@ -1129,7 +1129,7 @@ int w_newSpriteBatch(lua_State *L)
|
||||
{
|
||||
const char *usagestr = luaL_checkstring(L, 3);
|
||||
if (!vertex::getConstant(usagestr, usage))
|
||||
return luaL_error(L, "Invalid usage hint: %s", usagestr);
|
||||
return luax_enumerror(L, "usage hint", vertex::getConstants(usage), usagestr);
|
||||
}
|
||||
|
||||
SpriteBatch *t = nullptr;
|
||||
@@ -1195,7 +1195,7 @@ int w_newCanvas(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, -1);
|
||||
if (!getConstant(str, settings.format))
|
||||
return luaL_error(L, "Invalid pixel format: %s", str);
|
||||
return luax_enumerror(L, "pixel format", str);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
@@ -1204,7 +1204,7 @@ int w_newCanvas(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, -1);
|
||||
if (!Texture::getConstant(str, settings.type))
|
||||
return luaL_error(L, "Invalid texture type: %s", str);
|
||||
return luax_enumerror(L, "texture type", Texture::getConstants(settings.type), str);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
@@ -1221,7 +1221,7 @@ int w_newCanvas(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, -1);
|
||||
if (!Canvas::getConstant(str, settings.mipmaps))
|
||||
return luaL_error(L, "Invalid Canvas mipmap mode: %s", str);
|
||||
return luax_enumerror(L, "Canvas mipmap mode", Canvas::getConstants(settings.mipmaps), str);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
@@ -1394,7 +1394,7 @@ static vertex::Usage luax_optmeshusage(lua_State *L, int idx, vertex::Usage def)
|
||||
const char *usagestr = lua_isnoneornil(L, idx) ? nullptr : luaL_checkstring(L, idx);
|
||||
|
||||
if (usagestr && !vertex::getConstant(usagestr, def))
|
||||
luaL_error(L, "Invalid usage hint: %s", usagestr);
|
||||
luax_enumerror(L, "usage hint", vertex::getConstants(def), usagestr);
|
||||
|
||||
return def;
|
||||
}
|
||||
@@ -1404,7 +1404,7 @@ static Mesh::DrawMode luax_optmeshdrawmode(lua_State *L, int idx, Mesh::DrawMode
|
||||
const char *modestr = lua_isnoneornil(L, idx) ? nullptr : luaL_checkstring(L, idx);
|
||||
|
||||
if (modestr && !Mesh::getConstant(modestr, def))
|
||||
luaL_error(L, "Invalid mesh draw mode: %s", modestr);
|
||||
luax_enumerror(L, "mesh draw mode", Mesh::getConstants(def), modestr);
|
||||
|
||||
return def;
|
||||
}
|
||||
@@ -1499,7 +1499,7 @@ static Mesh *newCustomMesh(lua_State *L)
|
||||
const char *tname = luaL_checkstring(L, -2);
|
||||
if (!Mesh::getConstant(tname, format.type))
|
||||
{
|
||||
luaL_error(L, "Invalid Mesh vertex data type name: %s", tname);
|
||||
luax_enumerror(L, "Mesh vertex data type name", Mesh::getConstants(format.type), tname);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1782,14 +1782,14 @@ int w_setBlendMode(lua_State *L)
|
||||
Graphics::BlendMode mode;
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(str, mode))
|
||||
return luaL_error(L, "Invalid blend mode: %s", str);
|
||||
return luax_enumerror(L, "blend mode", Graphics::getConstants(mode), str);
|
||||
|
||||
Graphics::BlendAlpha alphamode = Graphics::BLENDALPHA_MULTIPLY;
|
||||
if (!lua_isnoneornil(L, 2))
|
||||
{
|
||||
const char *alphastr = luaL_checkstring(L, 2);
|
||||
if (!Graphics::getConstant(alphastr, alphamode))
|
||||
return luaL_error(L, "Invalid blend alpha mode: %s", alphastr);
|
||||
return luax_enumerror(L, "blend alpha mode", Graphics::getConstants(alphamode), alphastr);
|
||||
}
|
||||
|
||||
luax_catchexcept(L, [&](){ instance()->setBlendMode(mode, alphamode); });
|
||||
@@ -1823,9 +1823,9 @@ int w_setDefaultFilter(lua_State *L)
|
||||
const char *magstr = luaL_optstring(L, 2, minstr);
|
||||
|
||||
if (!Texture::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.min), minstr);
|
||||
if (!Texture::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.mag), magstr);
|
||||
|
||||
f.anisotropy = (float) luaL_optnumber(L, 3, 1.0);
|
||||
|
||||
@@ -1856,7 +1856,7 @@ int w_setDefaultMipmapFilter(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Texture::getConstant(str, filter))
|
||||
return luaL_error(L, "Invalid filter mode: %s", str);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(filter), str);
|
||||
}
|
||||
|
||||
float sharpness = (float) luaL_optnumber(L, 2, 0);
|
||||
@@ -1896,7 +1896,7 @@ int w_setLineStyle(lua_State *L)
|
||||
Graphics::LineStyle style;
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(str, style))
|
||||
return luaL_error(L, "Invalid line style: %s", str);
|
||||
return luax_enumerror(L, "line style", Graphics::getConstants(style), str);
|
||||
|
||||
instance()->setLineStyle(style);
|
||||
return 0;
|
||||
@@ -1907,7 +1907,7 @@ int w_setLineJoin(lua_State *L)
|
||||
Graphics::LineJoin join;
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(str, join))
|
||||
return luaL_error(L, "Invalid line join mode: %s", str);
|
||||
return luax_enumerror(L, "line join", Graphics::getConstants(join), str);
|
||||
|
||||
instance()->setLineJoin(join);
|
||||
return 0;
|
||||
@@ -2373,7 +2373,7 @@ int w_printf(lua_State *L)
|
||||
|
||||
const char *astr = lua_isnoneornil(L, formatidx + 1) ? nullptr : luaL_checkstring(L, formatidx + 1);
|
||||
if (astr != nullptr && !Font::getConstant(astr, align))
|
||||
return luaL_error(L, "Incorrect alignment: %s", astr);
|
||||
return luax_enumerror(L, "alignment", Font::getConstants(align), astr);
|
||||
|
||||
if (font != nullptr)
|
||||
luax_catchexcept(L, [&](){ instance()->printf(str, font, wrap, align, m); });
|
||||
@@ -2526,7 +2526,7 @@ int w_rectangle(lua_State *L)
|
||||
Graphics::DrawMode mode;
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(str, mode))
|
||||
return luaL_error(L, "Invalid draw mode: %s", str);
|
||||
return luax_enumerror(L, "draw mode", Graphics::getConstants(mode), str);
|
||||
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
@@ -2558,7 +2558,7 @@ int w_circle(lua_State *L)
|
||||
Graphics::DrawMode mode;
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(str, mode))
|
||||
return luaL_error(L, "Invalid draw mode: %s", str);
|
||||
return luax_enumerror(L, "draw mode", Graphics::getConstants(mode), str);
|
||||
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
@@ -2580,7 +2580,7 @@ int w_ellipse(lua_State *L)
|
||||
Graphics::DrawMode mode;
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(str, mode))
|
||||
return luaL_error(L, "Invalid draw mode: %s", str);
|
||||
return luax_enumerror(L, "draw mode", Graphics::getConstants(mode), str);
|
||||
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
@@ -2603,7 +2603,7 @@ int w_arc(lua_State *L)
|
||||
Graphics::DrawMode drawmode;
|
||||
const char *drawstr = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(drawstr, drawmode))
|
||||
return luaL_error(L, "Invalid draw mode: %s", drawstr);
|
||||
return luax_enumerror(L, "draw mode", Graphics::getConstants(drawmode), drawstr);
|
||||
|
||||
int startidx = 2;
|
||||
|
||||
@@ -2613,7 +2613,7 @@ int w_arc(lua_State *L)
|
||||
{
|
||||
const char *arcstr = luaL_checkstring(L, 2);
|
||||
if (!Graphics::getConstant(arcstr, arcmode))
|
||||
return luaL_error(L, "Invalid arc mode: %s", arcstr);
|
||||
return luax_enumerror(L, "arc mode", Graphics::getConstants(arcmode), arcstr);
|
||||
|
||||
startidx = 3;
|
||||
}
|
||||
@@ -2642,7 +2642,7 @@ int w_polygon(lua_State *L)
|
||||
Graphics::DrawMode mode;
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
if (!Graphics::getConstant(str, mode))
|
||||
return luaL_error(L, "Invalid draw mode: %s", str);
|
||||
return luax_enumerror(L, "draw mode", Graphics::getConstants(mode), str);
|
||||
|
||||
bool is_table = false;
|
||||
if (args == 1 && lua_istable(L, 2))
|
||||
@@ -2704,7 +2704,7 @@ int w_push(lua_State *L)
|
||||
Graphics::StackType stype = Graphics::STACK_TRANSFORM;
|
||||
const char *sname = lua_isnoneornil(L, 1) ? nullptr : luaL_checkstring(L, 1);
|
||||
if (sname && !Graphics::getConstant(sname, stype))
|
||||
return luaL_error(L, "Invalid graphics stack type: %s", sname);
|
||||
return luax_enumerror(L, "graphics stack type", Graphics::getConstants(stype), sname);
|
||||
|
||||
luax_catchexcept(L, [&](){ instance()->push(stype); });
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -99,7 +99,7 @@ int w_ParticleSystem_setInsertMode(lua_State *L)
|
||||
ParticleSystem::InsertMode mode;
|
||||
const char *str = luaL_checkstring(L, 2);
|
||||
if (!ParticleSystem::getConstant(str, mode))
|
||||
return luaL_error(L, "Invalid insert mode: '%s'", str);
|
||||
return luax_enumerror(L, "insert mode", ParticleSystem::getConstants(mode), str);
|
||||
t->setInsertMode(mode);
|
||||
return 0;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ int w_ParticleSystem_setAreaSpread(lua_State *L)
|
||||
|
||||
const char *str = lua_isnoneornil(L, 2) ? 0 : luaL_checkstring(L, 2);
|
||||
if (str && !ParticleSystem::getConstant(str, distribution))
|
||||
return luaL_error(L, "Invalid particle distribution: %s", str);
|
||||
return luax_enumerror(L, "particle distribution", ParticleSystem::getConstants(distribution), str);
|
||||
|
||||
if (distribution != ParticleSystem::DISTRIBUTION_NONE)
|
||||
{
|
||||
|
||||
@@ -163,7 +163,7 @@ int w_Shader_sendMatrices(lua_State *L, int startidx, Shader *shader, const Shad
|
||||
const char *layoutstr = lua_tostring(L, startidx);
|
||||
math::Transform::MatrixLayout layout;
|
||||
if (!math::Transform::getConstant(layoutstr, layout))
|
||||
return luaL_error(L, "Invalid matrix layout: %s", layoutstr);
|
||||
return luax_enumerror(L, "matrix layout", math::Transform::getConstants(layout), layoutstr);
|
||||
|
||||
columnmajor = (layout == math::Transform::MATRIX_COLUMN_MAJOR);
|
||||
startidx++;
|
||||
@@ -316,7 +316,7 @@ static int w_Shader_sendData(lua_State *L, int startidx, Shader *shader, const S
|
||||
const char *layoutstr = lua_tostring(L, startidx + 1);
|
||||
math::Transform::MatrixLayout layout;
|
||||
if (!math::Transform::getConstant(layoutstr, layout))
|
||||
return luaL_error(L, "Invalid matrix layout: %s", layoutstr);
|
||||
return luax_enumerror(L, "matrix layout", math::Transform::getConstants(layout), layoutstr);
|
||||
|
||||
columnmajor = (layout == math::Transform::MATRIX_COLUMN_MAJOR);
|
||||
startidx++;
|
||||
|
||||
@@ -52,7 +52,7 @@ int w_Text_setf(lua_State *L)
|
||||
Font::AlignMode align;
|
||||
const char *alignstr = luaL_checkstring(L, 4);
|
||||
if (!Font::getConstant(alignstr, align))
|
||||
return luaL_error(L, "Invalid align mode: %s", alignstr);
|
||||
return luax_enumerror(L, "align mode", Font::getConstants(align), alignstr);
|
||||
|
||||
std::vector<Font::ColoredString> newtext;
|
||||
luax_checkcoloredstring(L, 2, newtext);
|
||||
@@ -111,7 +111,7 @@ int w_Text_addf(lua_State *L)
|
||||
const char *alignstr = luaL_checkstring(L, 4);
|
||||
|
||||
if (!Font::getConstant(alignstr, align))
|
||||
return luaL_error(L, "Invalid align mode: %s", alignstr);
|
||||
return luax_enumerror(L, "align mode", Font::getConstants(align), alignstr);
|
||||
|
||||
if (luax_istype(L, 5, math::Transform::type))
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ int w_Texture_getTextureType(lua_State *L)
|
||||
Texture *t = luax_checktexture(L, 1);
|
||||
const char *tstr;
|
||||
if (!Texture::getConstant(t->getTextureType(), tstr))
|
||||
return luaL_error(L, "unknown texture type");
|
||||
return luax_enumerror(L, "texture type", Texture::getConstants(TEXTURE_MAX_ENUM), tstr);
|
||||
lua_pushstring(L, tstr);
|
||||
return 1;
|
||||
}
|
||||
@@ -138,9 +138,9 @@ int w_Texture_setFilter(lua_State *L)
|
||||
const char *magstr = luaL_optstring(L, 3, minstr);
|
||||
|
||||
if (!Texture::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.min), minstr);
|
||||
if (!Texture::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.mag), magstr);
|
||||
|
||||
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
|
||||
|
||||
@@ -178,7 +178,7 @@ int w_Texture_setMipmapFilter(lua_State *L)
|
||||
{
|
||||
const char *mipmapstr = luaL_checkstring(L, 2);
|
||||
if (!Texture::getConstant(mipmapstr, f.mipmap))
|
||||
return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.mipmap), mipmapstr);
|
||||
}
|
||||
|
||||
luax_catchexcept(L, [&](){ t->setFilter(f); });
|
||||
@@ -213,11 +213,11 @@ int w_Texture_setWrap(lua_State *L)
|
||||
const char *rstr = luaL_optstring(L, 4, sstr);
|
||||
|
||||
if (!Texture::getConstant(sstr, w.s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", sstr);
|
||||
return luax_enumerror(L, "wrap mode", Texture::getConstants(w.s), sstr);
|
||||
if (!Texture::getConstant(tstr, w.t))
|
||||
return luaL_error(L, "Invalid wrap mode, %s", tstr);
|
||||
return luax_enumerror(L, "wrap mode", Texture::getConstants(w.t), tstr);
|
||||
if (!Texture::getConstant(rstr, w.r))
|
||||
return luaL_error(L, "Invalid wrap mode, %s", rstr);
|
||||
return luax_enumerror(L, "wrap mode", Texture::getConstants(w.r), rstr);
|
||||
|
||||
luax_pushboolean(L, t->setWrap(w));
|
||||
return 1;
|
||||
@@ -275,7 +275,7 @@ int w_Texture_setDepthSampleMode(lua_State *L)
|
||||
|
||||
mode.hasValue = true;
|
||||
if (!getConstant(str, mode.value))
|
||||
return luaL_error(L, "Invalid compare mode: %s", str);
|
||||
return luax_enumerror(L, "compare mode", getConstants(mode.value), str);
|
||||
}
|
||||
|
||||
luax_catchexcept(L, [&]() { t->setDepthSampleMode(mode); });
|
||||
|
||||
@@ -119,9 +119,9 @@ int w_Video_setFilter(lua_State *L)
|
||||
const char *magstr = luaL_optstring(L, 3, minstr);
|
||||
|
||||
if (!Texture::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.min), minstr);
|
||||
if (!Texture::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
return luax_enumerror(L, "filter mode", Texture::getConstants(f.mag), magstr);
|
||||
|
||||
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user