Software /
code /
prosody
Annotate
util/import.lua @ 49:1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 04 Oct 2008 02:43:23 +0100 |
child | 519:cccd610a0ef9 |
rev | line source |
---|---|
49
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local t_insert = table.insert; |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 function import(module, ...) |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local m = package.loaded[module] or require(module); |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 if type(m) == "table" and ... then |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local ret = {}; |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 for _, f in ipairs{...} do |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 t_insert(ret, m[f]); |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 end |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 return unpack(ret); |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 end |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 return m; |
1cd2a8db392d
New "import" module to help tidy up all the local declarations at the top of modules
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |