From 2907fa06a752319edfc8c3848d4c92671e96d4b4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 23 Feb 2014 15:28:20 -0500 Subject: [PATCH] Try to resolve enums old-style if new-style fails This makes e.g. cmd(blend,add) work like cmd(blend,'BlendMode_Add'). Resolution in this case is case-insensitive like it used to be. --- src/EnumHelper.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/EnumHelper.cpp b/src/EnumHelper.cpp index dec4665019..a7e7ec5b27 100644 --- a/src/EnumHelper.cpp +++ b/src/EnumHelper.cpp @@ -22,6 +22,24 @@ int CheckEnum( lua_State *L, LuaReference &table, int iPos, int iInvalid, const lua_pushvalue( L, iPos ); lua_gettable( L, -2 ); + // If not found, check case-insensitively for legacy compatibility + if( lua_isnil(L, -1) && lua_isstring(L, iPos) ) { + RString sLower; + + // Get rid of nil value on stack + lua_pop( L, 1 ); + + // Get the string and lowercase it + lua_pushvalue( L, iPos ); + LuaHelpers::Pop( L, sLower ); + sLower.MakeLower(); + + // Try again to read the value + table.PushSelf( L ); + LuaHelpers::Push( L, sLower ); + lua_gettable( L, -2 ); + } + // If the result is nil, then a string was passed that is not a member of this enum. Throw // an error. To specify the invalid value, pass nil. That way, typos will throw an error, // and not silently result in nil, or an out-of-bounds value.