From fdd3d58eafbe058d64d48b1467693626302004f0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 4 Apr 2018 15:40:08 +0200 Subject: [PATCH] lua: Add a function to convert to the current codepage This will help VLSub handle non ascii path on windows --- modules/lua/libs/strings.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/lua/libs/strings.c b/modules/lua/libs/strings.c index 66fb754c8f..7709279916 100644 --- a/modules/lua/libs/strings.c +++ b/modules/lua/libs/strings.c @@ -175,6 +175,24 @@ static int vlclua_from_charset( lua_State *L ) return 1; } +static int vlclua_to_codepage( lua_State *L ) +{ + if( lua_gettop( L ) < 1 ) return vlclua_error( L ); + +#ifdef _WIN32 + const char *psz_input = luaL_checkstring( L, 1 ); + + char* psz_output = ToANSI( psz_input ); + lua_pushstring( L, psz_output ? psz_output : "" ); + free( psz_output ); + return 1; +#else + const char *psz_input = luaL_checkstring( L, 1 ); + lua_pushstring( L, psz_input ); + return 1; +#endif +} + /***************************************************************************** * *****************************************************************************/ @@ -187,6 +205,7 @@ static const luaL_Reg vlclua_strings_reg[] = { { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars }, { "convert_xml_special_chars", vlclua_convert_xml_special_chars }, { "from_charset", vlclua_from_charset }, + { "to_codepage", vlclua_to_codepage }, { NULL, NULL } }; -- 2.11.4.GIT