diff options
Diffstat (limited to '')
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index c5c2096..6f06131 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -77,10 +77,12 @@ local versions = { | |||
77 | 77 | ||
78 | -- Trying to capture best practices here for creating modules, especially since module() is broken and deprecated. | 78 | -- Trying to capture best practices here for creating modules, especially since module() is broken and deprecated. |
79 | -- TODO - Should parse in license type to. | 79 | -- TODO - Should parse in license type to. |
80 | moduleBegin = function (name, author, copyright, version, timestamp, skin) | 80 | moduleBegin = function (name, author, copyright, version, timestamp, skin, isLua) |
81 | local _M = {} -- This is what we return to require(). | 81 | local _M = {} -- This is what we return to require(). |
82 | local level = 2 | 82 | local level = 2 |
83 | 83 | ||
84 | if 'nil' == type(isLua) then isLua = true end | ||
85 | |||
84 | package.loaded[name] = _M -- Stuff the result into where require() can find it, instead of returning it at the end. | 86 | package.loaded[name] = _M -- Stuff the result into where require() can find it, instead of returning it at the end. |
85 | -- Returning it at the end does the same thing. | 87 | -- Returning it at the end does the same thing. |
86 | -- This is so that we can have all the module stuff at the top, in this function. | 88 | -- This is so that we can have all the module stuff at the top, in this function. |
@@ -102,6 +104,7 @@ moduleBegin = function (name, author, copyright, version, timestamp, skin) | |||
102 | _M._M = _M -- So that references to _M below the setfenv() actually go to the real _M. | 104 | _M._M = _M -- So that references to _M below the setfenv() actually go to the real _M. |
103 | _M._NAME = name | 105 | _M._NAME = name |
104 | _M._PACKAGE = string.gsub(_M._NAME, "[^.]*$", "") -- Strip the name down to the package name. | 106 | _M._PACKAGE = string.gsub(_M._NAME, "[^.]*$", "") -- Strip the name down to the package name. |
107 | _M.isLua = isLua | ||
105 | 108 | ||
106 | -- Parse in an entire copyright message, and strip that down into bits, to put back together. | 109 | -- Parse in an entire copyright message, and strip that down into bits, to put back together. |
107 | local date, owner = string.match(copyright, '[Cc]opyright (%d%d%d%d) (.*)') | 110 | local date, owner = string.match(copyright, '[Cc]opyright (%d%d%d%d) (.*)') |
@@ -129,12 +132,15 @@ moduleBegin = function (name, author, copyright, version, timestamp, skin) | |||
129 | 132 | ||
130 | setmetatable(_M, Thing) | 133 | setmetatable(_M, Thing) |
131 | _M.savedEnvironment = savedEnvironment | 134 | _M.savedEnvironment = savedEnvironment |
132 | -- setfenv() sets the environment for the FUNCTION, stack level deep. | 135 | -- NOTE - setfenv() wont work if the environment it refers to is a C function. Worse, getfenv() returns the global environment, so we can't tell. |
133 | -- The number is the stack level - | 136 | if isLua then |
134 | -- 0 running thread, 1 current function, 2 function that called this function, etc | 137 | -- setfenv() sets the environment for the FUNCTION, stack level deep. |
135 | setfenv(level, _M) -- Use the result for the modules internal global environment, so they don't need to qualify internal names. | 138 | -- The number is the stack level - |
139 | -- 0 running thread, 1 current function, 2 function that called this function, etc | ||
140 | setfenv(level, _M) -- Use the result for the modules internal global environment, so they don't need to qualify internal names. | ||
136 | -- Dunno if this causes problems with the do ... end style of joining modules. It does. So we need to restore in moduleEnd(). | 141 | -- Dunno if this causes problems with the do ... end style of joining modules. It does. So we need to restore in moduleEnd(). |
137 | -- Next question, does this screw with the environment of the skang module? No it doesn't, coz that's set up at require 'skang' time. | 142 | -- Next question, does this screw with the environment of the skang module? No it doesn't, coz that's set up at require 'skang' time. |
143 | end | ||
138 | 144 | ||
139 | print('Loaded module ' .. _M._NAME .. ' version ' .. _M.VERSION .. ', ' .. _M.COPYRIGHT .. '.\n ' .. _M.VERSION_DESC) | 145 | print('Loaded module ' .. _M._NAME .. ' version ' .. _M.VERSION .. ', ' .. _M.COPYRIGHT .. '.\n ' .. _M.VERSION_DESC) |
140 | 146 | ||
@@ -146,7 +152,7 @@ moduleEnd = function (module) | |||
146 | -- TODO - Look for _NAME.properties, and load it into the modules Things. | 152 | -- TODO - Look for _NAME.properties, and load it into the modules Things. |
147 | -- TODO - Parse command line parameters at some point. | 153 | -- TODO - Parse command line parameters at some point. |
148 | -- http://stackoverflow.com/questions/3745047/help-locate-c-sample-code-to-read-lua-command-line-arguments | 154 | -- http://stackoverflow.com/questions/3745047/help-locate-c-sample-code-to-read-lua-command-line-arguments |
149 | setfenv(2, module.savedEnvironment) | 155 | if module.isLua then setfenv(2, module.savedEnvironment) end |
150 | end | 156 | end |
151 | 157 | ||
152 | -- Call this now so that from now on, this is like any other module. | 158 | -- Call this now so that from now on, this is like any other module. |
@@ -424,6 +430,7 @@ thing = function (names, ...) | |||
424 | thing.required = params[5] or thing.required | 430 | thing.required = params[5] or thing.required |
425 | thing.acl = params[6] or thing.acl | 431 | thing.acl = params[6] or thing.acl |
426 | thing.boss = params[7] or thing.boss | 432 | thing.boss = params[7] or thing.boss |
433 | thing.module = params[8] or thing.module -- Mostly for things like C functions, where get/setfenv() wont do what we need. | ||
427 | 434 | ||
428 | -- PUll out named arguments. | 435 | -- PUll out named arguments. |
429 | for k, v in pairs(params) do | 436 | for k, v in pairs(params) do |