diff options
| author | ruki <[email protected]> | 2017-12-07 22:46:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-08 14:10:23 +0800 |
| commit | cb44535305f596bd757ffb58e5ae3cde6d3589fa (patch) | |
| tree | 343f0ff9287b90204a6a000e0af1a7a1ed6c640b /xmake/core/base | |
| parent | abe87994168053e4f420a8b7ab286c65b546eaae (diff) | |
improve log and add color attrs for curses
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/log.lua | 42 | ||||
| -rw-r--r-- | xmake/core/base/object.lua | 18 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 18 |
4 files changed, 35 insertions, 45 deletions
diff --git a/xmake/core/base/log.lua b/xmake/core/base/log.lua index e9b05f8c1..3ba6589a0 100644 --- a/xmake/core/base/log.lua +++ b/xmake/core/base/log.lua @@ -26,11 +26,11 @@ local log = log or {} -- get the log file -function log.file() +function log:file() -- get the output file - if log._FILE == nil then - local outputfile = log.outputfile() + if self._FILE == nil then + local outputfile = self:outputfile() if outputfile then -- get directory @@ -48,48 +48,48 @@ function log.file() end -- open the log file - log._FILE = io.open(outputfile, 'w+') + self._FILE = io.open(outputfile, 'w+') end - log._FILE = log._FILE or false + self._FILE = self._FILE or false end - return log._FILE + return self._FILE end -- get the output file -function log.outputfile() - if log._LOGFILE == nil then - log._LOGFILE = os.getenv("XMAKE_LOGFILE") or false +function log:outputfile() + if self._LOGFILE == nil then + self._LOGFILE = os.getenv("XMAKE_LOGFILE") or false end - return log._LOGFILE + return self._LOGFILE end -- flush log to file -function log.flush() - local file = log.file() +function log:flush() + local file = log:file() if file then io.flush(file) end end -- close the log file -function log.close() - local file = log.file() +function log:close() + local file = log:file() if file then file:close() end end -- print log to the log file -function log.print(...) - local file = log.file() +function log:print(...) + local file = log:file() if file then file:write(string.format(...) .. "\n") end end -- print variables to the log file -function log.printv(...) - local file = log.file() +function log:printv(...) + local file = log:file() if file then local values = {...} for i, v in ipairs(values) do @@ -108,8 +108,8 @@ function log.printv(...) end -- printf log to the log file -function log.printf(...) - local file = log.file() +function log:printf(...) + local file = self:file() if file then file:write(string.format(...)) end @@ -117,7 +117,7 @@ end -- write log the log file function log:write(...) - local file = log.file() + local file = self:file() if file then file:write(...) end diff --git a/xmake/core/base/object.lua b/xmake/core/base/object.lua index 1922b0b4d..ab4bf468f 100644 --- a/xmake/core/base/object.lua +++ b/xmake/core/base/object.lua @@ -28,20 +28,10 @@ local object = object or {} -- taken from 'std' library: http://luaforge.net/projects/stdlib/ -- and http://lua-cui.sourceforge.net/ -- --- create an object/class: --- > object/class = parent {value, ...; field = value ...} --- > An object's metatable is itself. --- > In the initialiser, unnamed values are assigned to the fields --- > given by _init (assuming the default _clone). --- > Private fields and methods start with "_" --- > --- --- Access an object field: object.field --- > Call an object method: object:method (...) --- > Call a class method: class.method (self, ...) --- > --- > Add a field: object.field = x --- > Add a method: function object:method (...) ... end +-- local point = object { _init = {"x", "y"} } +-- +-- local p1 = point {1, 2} +-- > p1 {x = 1, y = 2} -- -- permute some indices of a table diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index e311af3a3..00b38f60a 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -653,7 +653,7 @@ end function os.raise(msg, ...) -- flush log - log.flush() + log:flush() -- flush io buffer io.flush() diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index e28938648..8a31330e7 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -78,7 +78,7 @@ function utils.print(format, ...) utils._print(message) -- write to the log file - log.printv(message) + log:printv(message) end -- print format string without newline @@ -94,7 +94,7 @@ function utils.printf(format, ...) utils._iowrite(message) -- write to the log file - log.write(message) + log:write(message) end -- print format string and colors with newline @@ -110,8 +110,8 @@ function utils.cprint(format, ...) utils._print(colors.translate(message)) -- write to the log file - if log.file() then - log.printv(colors.ignore(message)) + if log:file() then + log:printv(colors.ignore(message)) end end @@ -128,8 +128,8 @@ function utils.cprintf(format, ...) utils._iowrite(colors.translate(message)) -- write to the log file - if log.file() then - log.write(colors.ignore(message)) + if log:file() then + log:write(colors.ignore(message)) end end @@ -148,7 +148,7 @@ function utils.verror(format, ...) -- enable verbose? if option.get("verbose") and format ~= nil then utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...)) - log.flush() + log:flush() end end @@ -158,7 +158,7 @@ function utils.error(format, ...) -- trace if format ~= nil then utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...)) - log.flush() + log:flush() end end @@ -182,7 +182,7 @@ function utils.warning(format, ...) end -- flush - log.flush() + log:flush() end -- ifelse, a? b : c |
