diff --git a/src/scripting/lua_common.cpp b/src/scripting/lua_common.cpp index 62442d9e55e5..6dd563a3ed0d 100644 --- a/src/scripting/lua_common.cpp +++ b/src/scripting/lua_common.cpp @@ -595,6 +595,17 @@ t_string luaW_checktstring(lua_State *L, int index) return result; } +bool luaW_isstring(lua_State* L, int index) +{ + if(lua_isstring(L, index)) { + return true; + } + if(lua_isuserdata(L, index) && luaL_testudata(L, index, tstringKey)) { + return true; + } + return false; +} + void luaW_filltable(lua_State *L, const config& cfg) { if (!lua_checkstack(L, LUA_MINSTACK)) diff --git a/src/scripting/lua_common.hpp b/src/scripting/lua_common.hpp index 635c67f1dadd..8f4da0220be9 100644 --- a/src/scripting/lua_common.hpp +++ b/src/scripting/lua_common.hpp @@ -78,6 +78,12 @@ bool luaW_totstring(lua_State *L, int index, t_string &str); */ t_string luaW_checktstring(lua_State *L, int index); +/* + * Test if a scalar is either a plain or translatable string. + * Also returns true if it's a number since that's convertible to string. + */ +bool luaW_isstring(lua_State* L, int index); + /** * Converts a config object to a Lua table. * The destination table should be at the top of the stack on entry. It is