From cbd72e937d95eafc188601bf50de7eb29d8c6cf0 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 11 Feb 2018 13:20:46 -0500 Subject: [PATCH] Utility function that I didn't end up using but which could be useful elsewhere --- src/scripting/lua_common.cpp | 11 +++++++++++ src/scripting/lua_common.hpp | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/scripting/lua_common.cpp b/src/scripting/lua_common.cpp index 62442d9e55e52..6dd563a3ed0db 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 635c67f1dadda..8f4da0220be95 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