[vlc-commits] lua: Add a function to convert to the current codepage

Hugo Beauzée-Luyssen git at videolan.org
Thu Apr 5 10:26:07 CEST 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Apr  4 15:40:08 2018 +0200| [fdd3d58eafbe058d64d48b1467693626302004f0] | committer: Hugo Beauzée-Luyssen

lua: Add a function to convert to the current codepage

This will help VLSub handle non ascii path on windows

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fdd3d58eafbe058d64d48b1467693626302004f0
---

 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 }
 };
 



More information about the vlc-commits mailing list