fix os.host

This commit is contained in:
ruki
2018-11-20 00:31:46 +08:00
parent af34ce822c
commit 1f9b177f72
6 changed files with 36 additions and 21 deletions

View File

@@ -63,6 +63,14 @@ Notes:
#include <stdlib.h>
#include <string.h>
#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"

View File

@@ -22,3 +22,6 @@ target("lcurses")
else
add_links("curses")
end
-- set languages
set_languages("c89")

View File

@@ -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")

View File

@@ -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

View File

@@ -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

View File

@@ -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 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
elseif os.run("cmd /c ver") == 0 then
os._HOST = "windows"
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