summaryrefslogtreecommitdiff
path: root/xmake/core/language/language.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2017-01-05 13:20:57 +0800
committerruki <[email protected]>2017-01-06 17:20:08 +0800
commit63463f04bee8ea369c2bbe0306f1e9316333f0dc (patch)
treebdc6c663fa8877f20779d6032c18db84c2626440 /xmake/core/language/language.lua
parent06a7207823add9becd9f0929c9ed1b4eb2a1ab44 (diff)
uses loaded return value for language and platform
Diffstat (limited to 'xmake/core/language/language.lua')
-rw-r--r--xmake/core/language/language.lua75
1 files changed, 13 insertions, 62 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua
index f1134d614..566b1ccdc 100644
--- a/xmake/core/language/language.lua
+++ b/xmake/core/language/language.lua
@@ -34,60 +34,6 @@ local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local global = require("project/global")
--- load the language module
-function _instance:_load(modulename)
-
- -- return it directly if cached
- local cachename = "_" .. modulename:upper()
- if self[cachename] then
- return self[cachename]
- end
-
- -- no this module?
- if not self._INFO[modulename] then
- return nil
- end
-
- -- get the script path
- local scriptpath = path.join(self._ROOTDIR, self._INFO[modulename] .. ".lua")
-
- -- not exists?
- if not scriptpath or not os.isfile(scriptpath) then
- return nil, string.format("the %s of %s not found!", modulename, self._NAME)
- end
-
- -- load script
- local script, errors = loadfile(scriptpath)
- if script then
-
- -- make sandbox instance with the given script
- local instance, errors = sandbox.new(script, nil, self._ROOTDIR)
- if not instance then
- return nil, errors
- end
-
- -- import the module
- local module, errors = instance:import()
- if not module then
- return nil, errors
- end
-
- -- init the module
- if module.init then
- module.init()
- end
-
- -- save it to the cache
- self[cachename] = module
-
- -- ok?
- return module
- end
-
- -- failed
- return nil, errors
-end
-
-- new an instance
function _instance.new(name, info, rootdir)
@@ -109,23 +55,27 @@ function _instance:get(name)
-- the info
local info = self._INFO
- -- load it first
+ -- get if from info first
+ local value = info[name]
+ if value ~= nil then
+ return value
+ end
+
+ -- load _g
if self._g == nil and info.load ~= nil then
-- load it
- local ok, errors = sandbox.load(info.load)
+ local ok, results = sandbox.load(info.load)
if not ok then
- os.raise(errors)
+ os.raise(results)
end
-- save _g
- self._g = getfenv(info.load)._g
+ self._g = results
end
- -- get it
- if self._g ~= nil then
- return self._g[name]
- end
+ -- get it from _g
+ return self._g[name]
end
-- get the language sourcekinds
@@ -281,6 +231,7 @@ function language.apis()
os.raise(errors)
end
+
-- merge apis for each language
local apis = {values = {}, pathes = {}}
for name, instance in pairs(languages) do