Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/xlua.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2011-11-25 04:55:40 +0400
committerClement Farabet <clement.farabet@gmail.com>2011-11-25 04:55:40 +0400
commit1771ff39a40489e47efbfa57aa8e722a2b23f691 (patch)
tree1acad3e75e26c354c8cf86994d9f138b716e496f
parent863ca82b88eb18e64d65f9a72678831d71e68163 (diff)
Added python-like import
-rw-r--r--xlua.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/xlua.lua b/xlua.lua
index e1b41cf..562a8dd 100644
--- a/xlua.lua
+++ b/xlua.lua
@@ -335,6 +335,29 @@ end
glob.xrequire = require
--------------------------------------------------------------------------------
+-- import package's symbols globally
+--
+-- @param package package to load
+-- @package as import as (python-like import)
+--------------------------------------------------------------------------------
+function import(package, as)
+ require(package)
+ if as then
+ glob[as] = glob[package]
+ else
+ for k,v in pairs(glob[package]) do
+ if glob[k] then
+ print('warning: "' .. k .. '" defined both globally and in package "'
+ .. package .. '", skipping import')
+ else
+ glob[k] = v
+ end
+ end
+ end
+end
+glob.import = import
+
+--------------------------------------------------------------------------------
-- standard usage function: used to display automated help for functions
--
-- @param funcname function name