diff options
author | Clement Farabet <clement.farabet@gmail.com> | 2011-11-25 04:55:40 +0400 |
---|---|---|
committer | Clement Farabet <clement.farabet@gmail.com> | 2011-11-25 04:55:40 +0400 |
commit | 1771ff39a40489e47efbfa57aa8e722a2b23f691 (patch) | |
tree | 1acad3e75e26c354c8cf86994d9f138b716e496f | |
parent | 863ca82b88eb18e64d65f9a72678831d71e68163 (diff) |
Added python-like import
-rw-r--r-- | xlua.lua | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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 |