From d2a110761100b511cdc0c714f303a9a4dcb3f814 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Tue, 19 Nov 2013 23:03:53 -0500 Subject: Experimental winapi extension for preventing the flashing black box on Windows. Compile in a stripped version of Steve Donovan's winapi library and override `io.popen` and `os.execute`. --- core/file_io.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'core') diff --git a/core/file_io.lua b/core/file_io.lua index 1a017be7..cbd1bed9 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -415,3 +415,31 @@ function io.snapopen(paths, filter, exclude_FILTER, opts) for i = 1, #files do files[i] = files[i]:iconv(_CHARSET, 'UTF-8') end io.open_file(files) end + +-- On Windows, override `io.popen` and `os.execute` to use winapi to prevent the +-- flashing black box. +if WIN32 then + local winapi = require('winapi') + io.popen = function(prog) + local code, output = winapi.execute(prog) + if not code then return code, output end + return { + read = function() return output end, + lines = function() + if not output:find('\r?\n$') then output = output..'\n' end + local pos = 1 + return function() + local s, e, line = output:find('([^\r\n]*)\r?\n', pos) + if not s then return nil end + pos = e + 1 + return line + end + end, + close = function() return true, 'exit', code end + } + end + os.execute = function(prog) + local code = winapi.execute(prog) + if code then return true, 'exit', code end + end +end -- cgit v1.2.3