From 1f9b177f72b309f9f74ac0334b9f05a60a26120a Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 20 Nov 2018 00:31:46 +0800 Subject: [PATCH] fix os.host --- src/core/lcurses/lcurses.c | 8 ++++++++ src/core/lcurses/xmake.lua | 3 +++ src/core/pdcurses/xmake.lua | 3 +++ src/core/xmake.lua | 2 +- src/ltui/base/log.lua | 6 +++++- src/ltui/base/os.lua | 35 ++++++++++++++++------------------- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/core/lcurses/lcurses.c b/src/core/lcurses/lcurses.c index 1dbf340..9e90d0c 100644 --- a/src/core/lcurses/lcurses.c +++ b/src/core/lcurses/lcurses.c @@ -63,6 +63,14 @@ Notes: #include #include +#include "luaconf.h" +#undef LUA_API +#if defined(__cplusplus) +#define LUA_API extern "C" +#else +#define LUA_API extern +#endif + #include "luajit.h" #include "lualib.h" #include "lauxlib.h" diff --git a/src/core/lcurses/xmake.lua b/src/core/lcurses/xmake.lua index 4aea732..cd6384d 100644 --- a/src/core/lcurses/xmake.lua +++ b/src/core/lcurses/xmake.lua @@ -22,3 +22,6 @@ target("lcurses") else add_links("curses") end + + -- set languages + set_languages("c89") diff --git a/src/core/pdcurses/xmake.lua b/src/core/pdcurses/xmake.lua index 9abf533..8c735a3 100644 --- a/src/core/pdcurses/xmake.lua +++ b/src/core/pdcurses/xmake.lua @@ -7,6 +7,9 @@ target("pdcurses") -- add the common source files add_files("**.c") + -- add include directories + add_includedirs(".") + -- add defines add_defines("PDC_WIDE") diff --git a/src/core/xmake.lua b/src/core/xmake.lua index ef0fc9a..7f65c9d 100644 --- a/src/core/xmake.lua +++ b/src/core/xmake.lua @@ -25,7 +25,7 @@ if is_plat("windows") then add_cxflags("-MT") add_defines("_CRT_SECURE_NO_WARNINGS") add_shflags("-nodefaultlib:msvcrt.lib") - add_links("kernel32", "user32", "gdi32") + add_links("kernel32", "user32", "gdi32", "advapi32") end -- add requires diff --git a/src/ltui/base/log.lua b/src/ltui/base/log.lua index 2388dc0..00c2796 100644 --- a/src/ltui/base/log.lua +++ b/src/ltui/base/log.lua @@ -66,7 +66,11 @@ end -- clear log function log:clear(state) if os.isfile(self:outputfile()) then - io.writefile(self:outputfile(), "") + local file = io.open(self:outputfile(), "w") + if file then + file:write("") + file:close() + end end end diff --git a/src/ltui/base/os.lua b/src/ltui/base/os.lua index 51800c8..f949e91 100644 --- a/src/ltui/base/os.lua +++ b/src/ltui/base/os.lua @@ -58,29 +58,32 @@ end -- run program and get io output function os.iorun(cmd, ...) - local ok = false local outs = nil local file = io.popen(string.tryformat(cmd, ...), "r") if file then outs = file:read("*a"):trim() file:close() - ok = true end - return ok, outs + return outs end -- get host name function os.host() if os._HOST == nil then - local ok, result = os.iorun("uname") - if ok then - if result:lower():find("linux", 1, true) then - os._HOST = "linux" - elseif result:lower():find("darwin", 1, true) then - os._HOST = "macosx" - end - elseif os.run("cmd /c ver") == 0 then + if jit and jit.os then + local hosts = {OSX = "macosx", Windows = "windows", Linux = "linux"} + os._HOST = hosts[jit.os] + elseif package.config:sub(1, 1) == '\\' then os._HOST = "windows" + else + local result = os.iorun("uname") + if result then + if result:lower():find("linux", 1, true) then + os._HOST = "linux" + elseif result:lower():find("darwin", 1, true) then + os._HOST = "macosx" + end + end end end return os._HOST @@ -89,15 +92,9 @@ end -- read string data from pasteboard function os.pbpaste() if os.host() == "macosx" then - local ok, result = os.iorun("pbpaste") - if ok then - return result - end + return os.iorun("pbpaste") elseif os.host() == "linux" then - local ok, result = os.iorun("xsel --clipboard --output") - if ok then - return result - end + return os.iorun("xsel --clipboard --output") else -- TODO end