diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index b59e12cf3..999232c35 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -964,6 +964,21 @@ static int libd_stringWidth(lua_State *L) return 1; } +static int libd_parseText(lua_State *L) +{ + HUDONLY + + const char *rawText = luaL_checkstring(L, 1); + + if (!rawText) + return luaL_error(L, "no string provided to v.parseText"); + + char *newText = V_ParseText(rawText); + lua_pushstring(gL, newText); + Z_Free(newText); + return 1; +} + static int libd_getColormap(lua_State *L) { INT32 skinnum = TC_DEFAULT; @@ -1162,6 +1177,7 @@ static luaL_Reg lib_draw[] = { // misc {"stringWidth", libd_stringWidth}, {"titleCardStringWidth", libd_titleCardStringWidth}, + {"parseText", libd_parseText}, // m_random {"RandomFixed",libd_RandomFixed}, {"RandomByte",libd_RandomByte}, diff --git a/src/v_video.cpp b/src/v_video.cpp index 0f278cf79..3772cb99a 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -3700,3 +3700,10 @@ void VID_DisplaySoftwareScreen() // Post-process blit to the 'default' framebuffer hw_state->blit_postimg_screens->draw(*rhi, ctx); } + +char *V_ParseText(const char *rawText) +{ + using srb2::Draw; + + return Z_StrDup(srb2::Draw::TextElement().parse(rawText).string().c_str()); +} diff --git a/src/v_video.h b/src/v_video.h index 018cd2c51..61467e641 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -442,6 +442,9 @@ void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT3 */ void VID_DisplaySoftwareScreen(void); +char *V_ParseText(const char *rawText); // Launder srb2::draw::TextElement.parse() through C code! + + #ifdef __cplusplus } // extern "C" #endif