diff options
| author | ruki <[email protected]> | 2016-03-26 20:51:35 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-26 20:51:35 +0800 |
| commit | f599ffc2ca8f452b70e2fb928816c5b78302ee1b (patch) | |
| tree | 59cf1fa8ad1cc2a9013641fac59e42d52cabb64e | |
| parent | 2d269f2eb8a61c7b4225a766ceedec4fd1858e95 (diff) | |
modify self interfaces
| -rw-r--r-- | xmake/core/base/deprecated/interpreter.lua | 8 | ||||
| -rw-r--r-- | xmake/core/base/filter.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 68 | ||||
| -rw-r--r-- | xmake/core/base/io.lua | 18 | ||||
| -rw-r--r-- | xmake/core/base/profiler.lua | 34 | ||||
| -rw-r--r-- | xmake/core/base/string.lua | 16 | ||||
| -rw-r--r-- | xmake/core/main.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/task.lua | 6 | ||||
| -rw-r--r-- | xmake/core/project/template.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 22 |
11 files changed, 107 insertions, 72 deletions
diff --git a/xmake/core/base/deprecated/interpreter.lua b/xmake/core/base/deprecated/interpreter.lua index 8ed452588..22e0cde00 100644 --- a/xmake/core/base/deprecated/interpreter.lua +++ b/xmake/core/base/deprecated/interpreter.lua @@ -32,7 +32,7 @@ local string = require("base/string") local sandbox = require("sandbox/sandbox") -- register api for set_scope() -function deprecated_interpreter.api_register_set_scope(self, ...) +function deprecated_interpreter:api_register_set_scope(...) -- check assert(self) @@ -71,7 +71,7 @@ function deprecated_interpreter.api_register_set_scope(self, ...) end -- register api for add_scope() -function deprecated_interpreter.api_register_add_scope(self, ...) +function deprecated_interpreter:api_register_add_scope(...) -- check assert(self) @@ -110,7 +110,7 @@ function deprecated_interpreter.api_register_add_scope(self, ...) end -- register api for set_script -function deprecated_interpreter.api_register_set_script(self, scope_kind, prefix, ...) +function deprecated_interpreter:api_register_set_script(scope_kind, prefix, ...) -- check assert(self) @@ -122,7 +122,7 @@ function deprecated_interpreter.api_register_set_script(self, scope_kind, prefix utils.warning("please uses on_%s(), \"set_%s()\" has been deprecated!", name, name, scope) -- make sandbox instance with the given script - local instance, errors = sandbox.make(script, self) + local instance, errors = sandbox.new(script, self) if not instance then os.raise("set_%s(): %s", name, errors) end diff --git a/xmake/core/base/filter.lua b/xmake/core/base/filter.lua index faacbafc2..a23bc25a4 100644 --- a/xmake/core/base/filter.lua +++ b/xmake/core/base/filter.lua @@ -47,7 +47,7 @@ function filter.init(handler) end -- filter the builtin variables: "hello $(variable)" for string -function filter.handle(self, value) +function filter:handle(value) -- check assert(type(value) == "string") diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 127663c40..74eb4fa18 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -74,7 +74,7 @@ function interpreter._traceback(errors) end -- register api: xxx_apiname() -function interpreter._api_register_xxx_scope(self, action, apifunc, ...) +function interpreter:_api_register_xxx_scope(action, apifunc, ...) -- check assert(self and self._PUBLIC and self._PRIVATE) @@ -109,7 +109,7 @@ function interpreter._api_register_xxx_scope(self, action, apifunc, ...) end -- register api: xxx_values() -function interpreter._api_register_xxx_values(self, scope_kind, action, prefix, apifunc, ...) +function interpreter:_api_register_xxx_values(scope_kind, action, prefix, apifunc, ...) -- check assert(self and self._PUBLIC and self._PRIVATE) @@ -154,7 +154,7 @@ function interpreter._api_register_xxx_values(self, scope_kind, action, prefix, end -- translate api pathes -function interpreter._api_translate_pathes(self, ...) +function interpreter:_api_translate_pathes(...) -- check assert(self and self._PRIVATE) @@ -185,7 +185,7 @@ function interpreter._api_translate_pathes(self, ...) end -- the builtin api: add_subdirs() or add_subfiles() -function interpreter._api_builtin_add_subdirfiles(self, isdirs, ...) +function interpreter:_api_builtin_add_subdirfiles(isdirs, ...) -- check assert(self and self._PRIVATE and self._PRIVATE._ROOTDIR and self._PRIVATE._MTIMES) @@ -248,7 +248,7 @@ function interpreter._api_builtin_add_subdirfiles(self, isdirs, ...) end -- clear results -function interpreter._clear(self) +function interpreter:_clear() -- check assert(self and self._PRIVATE) @@ -259,7 +259,7 @@ function interpreter._clear(self) end -- filter values -function interpreter._filter(self, values) +function interpreter:_filter(values) -- check assert(self and values) @@ -315,7 +315,7 @@ function interpreter._filter(self, values) end -- handle scope -function interpreter._handle(self, scope, remove_repeat, enable_filter) +function interpreter:_handle(scope, remove_repeat, enable_filter) -- check assert(scope) @@ -346,7 +346,7 @@ function interpreter._handle(self, scope, remove_repeat, enable_filter) end -- make results -function interpreter._make(self, scope_kind, remove_repeat, enable_filter) +function interpreter:_make(scope_kind, remove_repeat, enable_filter) -- check assert(self and self._PRIVATE) @@ -415,8 +415,8 @@ function interpreter._make(self, scope_kind, remove_repeat, enable_filter) return results end --- init interpreter -function interpreter.init() +-- new an interpreter instance +function interpreter.new() -- init an interpreter instance local instance = { _PUBLIC = {} @@ -447,7 +447,7 @@ function interpreter.init() end -- load results -function interpreter.load(self, file, scope_kind, remove_repeat, enable_filter) +function interpreter:load(file, scope_kind, remove_repeat, enable_filter) -- check assert(self and self._PUBLIC and self._PRIVATE and file) @@ -485,7 +485,7 @@ function interpreter.load(self, file, scope_kind, remove_repeat, enable_filter) end -- get mtimes -function interpreter.mtimes(self) +function interpreter:mtimes() -- check assert(self and self._PRIVATE) @@ -495,7 +495,7 @@ function interpreter.mtimes(self) end -- get filter -function interpreter.filter(self) +function interpreter:filter() -- check assert(self and self._PRIVATE) @@ -505,7 +505,7 @@ function interpreter.filter(self) end -- set filter -function interpreter.filter_set(self, filter) +function interpreter:filter_set(filter) -- check assert(self and self._PRIVATE) @@ -515,7 +515,7 @@ function interpreter.filter_set(self, filter) end -- get root directory -function interpreter.rootdir(self) +function interpreter:rootdir() -- check assert(self and self._PRIVATE) @@ -525,7 +525,7 @@ function interpreter.rootdir(self) end -- set root directory -function interpreter.rootdir_set(self, rootdir) +function interpreter:rootdir_set(rootdir) -- check assert(self and self._PRIVATE and rootdir) @@ -535,7 +535,7 @@ function interpreter.rootdir_set(self, rootdir) end -- register api -function interpreter.api_register(self, name, func) +function interpreter:api_register(name, func) -- check assert(self and self._PUBLIC) @@ -546,7 +546,7 @@ function interpreter.api_register(self, name, func) end -- register api for builtin -function interpreter.api_register_builtin(self, name, func) +function interpreter:api_register_builtin(name, func) -- check assert(self and self._PUBLIC and func) @@ -595,7 +595,7 @@ end -- } -- } -- -function interpreter.api_register_scope(self, ...) +function interpreter:api_register_scope(...) -- check assert(self) @@ -657,7 +657,7 @@ end -- } -- } -- -function interpreter.api_register_set_values(self, scope_kind, prefix, ...) +function interpreter:api_register_set_values(scope_kind, prefix, ...) -- check assert(self) @@ -676,7 +676,7 @@ function interpreter.api_register_set_values(self, scope_kind, prefix, ...) end -- register api for add_values -function interpreter.api_register_add_values(self, scope_kind, prefix, ...) +function interpreter:api_register_add_values(scope_kind, prefix, ...) -- check assert(self) @@ -695,7 +695,7 @@ function interpreter.api_register_add_values(self, scope_kind, prefix, ...) end -- register api for set_array -function interpreter.api_register_set_array(self, scope_kind, prefix, ...) +function interpreter:api_register_set_array(scope_kind, prefix, ...) -- check assert(self) @@ -714,7 +714,7 @@ function interpreter.api_register_set_array(self, scope_kind, prefix, ...) end -- register api for add_array -function interpreter.api_register_add_array(self, scope_kind, prefix, ...) +function interpreter:api_register_add_array(scope_kind, prefix, ...) -- check assert(self) @@ -733,7 +733,7 @@ function interpreter.api_register_add_array(self, scope_kind, prefix, ...) end -- register api for on_script -function interpreter.api_register_on_script(self, scope_kind, prefix, ...) +function interpreter:api_register_on_script(scope_kind, prefix, ...) -- check assert(self) @@ -742,7 +742,7 @@ function interpreter.api_register_on_script(self, scope_kind, prefix, ...) local implementation = function (self, scope, name, script) -- make sandbox instance with the given script - local instance, errors = sandbox.make(script, self) + local instance, errors = sandbox.new(script, self) if not instance then os.raise("on_%s(): %s", name, errors) end @@ -757,7 +757,7 @@ function interpreter.api_register_on_script(self, scope_kind, prefix, ...) end -- register api for set_keyvalues -function interpreter.api_register_set_keyvalues(self, scope_kind, prefix, ...) +function interpreter:api_register_set_keyvalues(scope_kind, prefix, ...) -- check assert(self) @@ -776,7 +776,7 @@ function interpreter.api_register_set_keyvalues(self, scope_kind, prefix, ...) end -- register api for add_keyvalues -function interpreter.api_register_add_keyvalues(self, scope_kind, prefix, ...) +function interpreter:api_register_add_keyvalues(scope_kind, prefix, ...) -- check assert(self) @@ -819,7 +819,7 @@ function interpreter.api_register_add_keyvalues(self, scope_kind, prefix, ...) end -- register api for set_pathes -function interpreter.api_register_set_pathes(self, scope_kind, prefix, ...) +function interpreter:api_register_set_pathes(scope_kind, prefix, ...) -- check assert(self) @@ -838,7 +838,7 @@ function interpreter.api_register_set_pathes(self, scope_kind, prefix, ...) end -- register api for add_pathes -function interpreter.api_register_add_pathes(self, scope_kind, prefix, ...) +function interpreter:api_register_add_pathes(scope_kind, prefix, ...) -- check assert(self) @@ -857,7 +857,7 @@ function interpreter.api_register_add_pathes(self, scope_kind, prefix, ...) end -- the builtin api: add_subdirs() -function interpreter.api_builtin_add_subdirs(self, ...) +function interpreter:api_builtin_add_subdirs(...) -- check assert(self) @@ -867,7 +867,7 @@ function interpreter.api_builtin_add_subdirs(self, ...) end -- the builtin api: add_subfiles() -function interpreter.api_builtin_add_subfiles(self, ...) +function interpreter:api_builtin_add_subfiles(...) -- check assert(self) @@ -877,7 +877,7 @@ function interpreter.api_builtin_add_subfiles(self, ...) end -- call api -function interpreter.api_call(self, apiname, ...) +function interpreter:api_call(apiname, ...) -- check assert(self and self._PUBLIC and apiname) @@ -893,7 +893,7 @@ function interpreter.api_call(self, apiname, ...) end -- save the current scope -function interpreter.scope_save(self) +function interpreter:scope_save() -- check assert(self and self._PRIVATE) @@ -912,7 +912,7 @@ function interpreter.scope_save(self) end -- restore the current scope -function interpreter.scope_restore(self, scope) +function interpreter:scope_restore(scope) -- check assert(self and self._PRIVATE and scope) diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua index ac23814f8..a93a01170 100644 --- a/xmake/core/base/io.lua +++ b/xmake/core/base/io.lua @@ -33,7 +33,7 @@ local utils = require("base/utils") io._open = io._open or io.open -- read file -function _file.read(self, ...) +function _file:read(...) -- check assert(self._FILE) @@ -43,7 +43,7 @@ function _file.read(self, ...) end -- write file -function _file.write(self, ...) +function _file:write(...) -- check assert(self._FILE) @@ -53,7 +53,7 @@ function _file.write(self, ...) end -- print file -function _file.print(self, ...) +function _file:print(...) -- check assert(self._FILE) @@ -63,7 +63,7 @@ function _file.print(self, ...) end -- printf file -function _file.printf(self, ...) +function _file:printf(...) -- check assert(self._FILE) @@ -73,7 +73,7 @@ function _file.printf(self, ...) end -- get lines -function _file.lines(self) +function _file:lines() -- check assert(self._FILE) @@ -83,7 +83,7 @@ function _file.lines(self) end -- close file -function _file.close(self) +function _file:close() -- check assert(self._FILE) @@ -93,7 +93,7 @@ function _file.close(self) end -- save object with the level -function _file._save(self, object, level) +function _file:_save(object, level) -- save string if type(object) == "string" then @@ -156,14 +156,14 @@ function _file._save(self, object, level) end -- save object -function _file.save(self, object) +function _file:save(object) -- save it return self:_save(object, 0) end -- load object -function _file.load(self) +function _file:load() -- check assert(self) diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua new file mode 100644 index 000000000..b0f0b3cf8 --- /dev/null +++ b/xmake/core/base/profiler.lua @@ -0,0 +1,34 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file profiler.lua +-- + +-- define module +local profiler = profiler or {} + +-- load modules +local os = require("base/os") +local table = require("base/table") +local utils = require("base/utils") +local string = require("base/string") + + +-- return module +return profiler diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua index fd931282c..7edbbde2d 100644 --- a/xmake/core/base/string.lua +++ b/xmake/core/base/string.lua @@ -24,7 +24,7 @@ local string = string or {} -- find the last substring with the given pattern -function string.find_last(self, pattern, plain) +function string:find_last(pattern, plain) -- find the last substring local curr = 0 @@ -42,7 +42,7 @@ function string.find_last(self, pattern, plain) end -- split string with the given pattern -function string.split(self, pattern) +function string:split(pattern) -- split it local list = {} @@ -51,24 +51,24 @@ function string.split(self, pattern) end -- trim the spaces -function string.trim(self) +function string:trim() return (self:gsub("^%s*(.-)%s*$", "%1")) end -- trim the left spaces -function string.ltrim(self) +function string:ltrim() return (self:gsub("^%s*", "")) end -- trim the right spaces -function string.rtrim(self) +function string:rtrim() local n = #self while n > 0 and s:find("^%s", n) do n = n - 1 end return self:sub(1, n) end -- append a substring with a given separator -function string.append(self, substr, separator) +function string:append(substr, separator) -- check assert(self) @@ -91,7 +91,7 @@ function string.append(self, substr, separator) end -- encode: ' ', '=', '\"', '<' -function string.encode(self) +function string:encode() -- null? if self == nil then return end @@ -101,7 +101,7 @@ function string.encode(self) end -- decode: ' ', '=', '\"' -function string.decode(self) +function string:decode() -- null? if self == nil then return end diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 5cb127971..78ffbd3fc 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -28,6 +28,7 @@ local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local option = require("base/option") +local profiler = require("base/profiler") local task = require("project/task") -- init the option menu diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 491eb4a44..6a98df001 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -322,7 +322,7 @@ function project._interpreter() end -- init interpreter - local interp = interpreter.init() + local interp = interpreter.new() assert(interp) -- set root directory diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua index b4664e66a..eb93012b2 100644 --- a/xmake/core/project/task.lua +++ b/xmake/core/project/task.lua @@ -52,7 +52,7 @@ function task._interpreter() end -- init interpreter - local interp = interpreter.init() + local interp = interpreter.new() assert(interp) -- register api: task() @@ -137,7 +137,7 @@ function task._bind(tasks) if type(opt) == "function" then -- make sandbox instance with the given script - local instance, errors = sandbox.make(opt, interp) + local instance, errors = sandbox.new(opt, interp) if not instance then return false, errors end @@ -169,7 +169,7 @@ function task._bind(tasks) if type(description) == "function" then -- make sandbox instance with the given script - local instance, errors = sandbox.make(description, interp) + local instance, errors = sandbox.new(description, interp) if not instance then return false, errors end diff --git a/xmake/core/project/template.lua b/xmake/core/project/template.lua index 688be7624..30ee76952 100644 --- a/xmake/core/project/template.lua +++ b/xmake/core/project/template.lua @@ -43,7 +43,7 @@ function template._interpreter() end -- init interpreter - local interp = interpreter.init() + local interp = interpreter.new() assert(interp) -- register api: set_description() and set_projectdir() diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index dd2dcc23c..637c69ce9 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -95,8 +95,8 @@ function sandbox._api_register_builtin(self, name, func) self._PUBLIC[name] = func end --- init sandbox -function sandbox._init() +-- new a sandbox instance +function sandbox._new() -- init an sandbox instance local instance = {_PUBLIC = {}, _PRIVATE = {}} @@ -150,14 +150,14 @@ function sandbox._init() return instance end --- make sandbox instance with the given script -function sandbox.make(script, interp) +-- new a sandbox instance with the given script +function sandbox.new(script, interp) -- check assert(script and interp) - -- init self - local self = sandbox._init() + -- new instance + local self = sandbox._new() -- check assert(self and self._PUBLIC and self._PRIVATE) @@ -208,7 +208,7 @@ function sandbox.load(script, ...) end -- fork a new sandbox from the given sandbox -function sandbox.fork(self, script) +function sandbox:fork(script) -- no script? if script == nil then @@ -221,7 +221,7 @@ function sandbox.fork(self, script) end -- init a new sandbox instance - local instance = sandbox._init() + local instance = sandbox._new() -- check assert(instance and instance._PUBLIC and instance._PRIVATE) @@ -243,7 +243,7 @@ function sandbox.fork(self, script) end -- get script from the given sandbox -function sandbox.script(self) +function sandbox:script() -- check assert(self and self._PRIVATE) @@ -253,7 +253,7 @@ function sandbox.script(self) end -- get filter from the given sandbox -function sandbox.filter(self) +function sandbox:filter() -- check assert(self and self._PRIVATE) @@ -263,7 +263,7 @@ function sandbox.filter(self) end -- get root directory from the given sandbox -function sandbox.rootdir(self) +function sandbox:rootdir() -- check assert(self and self._PRIVATE) |
