[vlc-devel] [PATCH 2/4] lua: console: Fix output of non ascii characters on win32

Hugo Beauzée-Luyssen hugo at beauzee.fr
Mon Mar 12 16:07:01 CET 2018


refs #19874
---
 modules/lua/libs/win.c          | 10 ++++++++++
 share/lua/intf/modules/host.lua |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/modules/lua/libs/win.c b/modules/lua/libs/win.c
index 14d6d30f78..7d0276331e 100644
--- a/modules/lua/libs/win.c
+++ b/modules/lua/libs/win.c
@@ -29,6 +29,7 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_charset.h>
 
 #include "../vlc.h"
 #include "../libs.h"
@@ -140,6 +141,14 @@ static int vlclua_console_read( lua_State *L )
     return 1;
 }
 
+static int vlclua_console_write( lua_State *L )
+{
+    if( !lua_isstring( L, 1 ) )
+        return luaL_error( L, "win.console_write usage: (text)" );
+    const char* psz_line = luaL_checkstring( L, 1 );
+    utf8_fprintf( stdout, "%s", psz_line );
+    return 0;
+}
 
 /*****************************************************************************
  *
@@ -148,6 +157,7 @@ static const luaL_Reg vlclua_win_reg[] = {
     { "console_init", vlclua_console_init },
     { "console_wait", vlclua_console_wait },
     { "console_read", vlclua_console_read },
+    { "console_write", vlclua_console_write },
     { NULL, NULL }
 };
 
diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua
index 1d84bbad94..7c99778319 100644
--- a/share/lua/intf/modules/host.lua
+++ b/share/lua/intf/modules/host.lua
@@ -124,7 +124,7 @@ function host()
     local function write_console( client, data )
         -- FIXME: this method shouldn't be needed. vlc.net.write should
         -- just work
-        io.write(data or client.buffer)
+        vlc.win.console_write(data or client.buffer)
         return string.len(data or client.buffer)
     end
 
-- 
2.11.0



More information about the vlc-devel mailing list