-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalloc_console.lua
More file actions
34 lines (30 loc) · 999 Bytes
/
Copy pathalloc_console.lua
File metadata and controls
34 lines (30 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if jit.os ~= 'Windows' then return function() end end
local ffi = require 'ffi'
local C = ffi.C
ffi.cdef[[
typedef int BOOL;
typedef void FILE;
BOOL AllocConsole(void);
FILE *freopen(const char *path, const char *mode, FILE *stream);
]]
-- https://github.com/love2d/love/blob/c59c85e04ce9bdc0e79c97a15eff55ff336dfee8/src/modules/love/love.cpp#L511
return function()
log.info 'allocating a new console as per request'
if C.AllocConsole() ~= 0 then
if C.freopen("CONOUT$", "w", io.stderr) == 0 then
log.warn 'could not reopen stderr for new console'
end
if C.freopen("CONOUT$", "w", io.stdout) == 0 then
log.warn 'could not reopen stdout for new console'
end
if C.freopen("CONIN$", "r", io.stdin) == 0 then
log.warn 'could not reopen stdin for new console'
end
else
local err = 'could not allocate new console, maybe already allocated?'
log.warn(err)
return false, err
end
log.info 'allocated a new console'
return true
end