diff options
author | David Walter Seikel | 2014-03-22 15:48:05 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-03-22 15:48:05 +1000 |
commit | 840a7c106b0f52794d4c170f462bfd5908f3fa60 (patch) | |
tree | 347138a338fb37391db6fb81778719825e813f92 /ClientHamr/GuiLua | |
parent | Dissolve ThingSpace, and commands & parameters. (diff) | |
download | SledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.zip SledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.tar.gz SledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.tar.bz2 SledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.tar.xz |
Remove the excess moduleBegin crap.
Diffstat (limited to 'ClientHamr/GuiLua')
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 39 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.lua | 2 |
2 files changed, 10 insertions, 31 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index a4d5e91..1eb7a64 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -58,8 +58,7 @@ The old skang argument types are - | |||
58 | -- By virtue of the fact we are stuffing our result into package.loaded[], just plain running this works as "loading the module". | 58 | -- By virtue of the fact we are stuffing our result into package.loaded[], just plain running this works as "loading the module". |
59 | do -- Only I'm not gonna indent this. | 59 | do -- Only I'm not gonna indent this. |
60 | 60 | ||
61 | -- This needs to start as local, then get wrapped a couple of times, eventually being made public as moduleBegin(). | 61 | moduleBegin = function (name, author, copyright, version, timestamp, skin) |
62 | local skangModuleBegin = function (name, author, copyright, version, timestamp, skin) | ||
63 | local _M = {} -- This is what we return to require(). | 62 | local _M = {} -- This is what we return to require(). |
64 | 63 | ||
65 | package.loaded[name] = _M -- Stuff the result into where require() can find it, instead of returning it at the end. | 64 | package.loaded[name] = _M -- Stuff the result into where require() can find it, instead of returning it at the end. |
@@ -102,21 +101,20 @@ local skangModuleBegin = function (name, author, copyright, version, timestamp, | |||
102 | -- setfenv() sets the environment for the FUNCTION, stack level deep. | 101 | -- setfenv() sets the environment for the FUNCTION, stack level deep. |
103 | -- The number is the stack level - | 102 | -- The number is the stack level - |
104 | -- 0 running thread, 1 current function, 2 function that called this function, etc | 103 | -- 0 running thread, 1 current function, 2 function that called this function, etc |
105 | setfenv(3, _M) -- Use the result for the modules internal global environment, so they don't need to qualify internal names. | 104 | setfenv(2, _M) -- Use the result for the modules internal global environment, so they don't need to qualify internal names. |
106 | -- Dunno if this causes problems with the do ... end style of joining modules. It does. So we need to restore in moduleEnd(). | 105 | -- Dunno if this causes problems with the do ... end style of joining modules. It does. So we need to restore in moduleEnd(). |
107 | -- 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. | 106 | -- 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. |
108 | 107 | ||
109 | return _M | 108 | return _M |
110 | end | 109 | end |
111 | 110 | ||
112 | -- This is so the setfenv() stack count above is correct, and we can access ThingSpace in the final moduleBegin() version below, and STILL use this for ourselves. lol | 111 | -- Call this now so that from now on, this is like any other module. |
113 | local smb = function (name, author, copyright, version, timestamp, skin) | 112 | local _M = moduleBegin('skang', 'David Seikel', '2014', '0.0', '2014-03-19 19:01:00') |
114 | local result = skangModuleBegin(name, author, copyright, version, timestamp, skin) | ||
115 | return result | ||
116 | end | ||
117 | 113 | ||
118 | -- Call this now, via the above wrapper, so that from now on, this is like any other module. | 114 | -- Restore the environment. |
119 | local _M = smb('skang', 'David Seikel', '2014', '0.0', '2014-03-19 19:01:00') | 115 | moduleEnd = function (module) |
116 | setfenv(2, module.savedEnvironment) | ||
117 | end | ||
120 | 118 | ||
121 | --[[ Thing package | 119 | --[[ Thing package |
122 | 120 | ||
@@ -176,11 +174,8 @@ Other Thing things are - | |||
176 | Also various functions to wrap checking the security, like canDo, canRead, etc. | 174 | Also various functions to wrap checking the security, like canDo, canRead, etc. |
177 | ]] | 175 | ]] |
178 | 176 | ||
179 | 177 | -- There is no ThingSpace, now it's just in this table - | |
180 | -- There is no ThingSpace, now it's just in these tables - | ||
181 | things = {} | 178 | things = {} |
182 | modules = {} | ||
183 | |||
184 | 179 | ||
185 | Thing = | 180 | Thing = |
186 | { | 181 | { |
@@ -253,22 +248,6 @@ Thing = | |||
253 | hasCrashed = 0, -- How many times this Thing has crashed. | 248 | hasCrashed = 0, -- How many times this Thing has crashed. |
254 | } | 249 | } |
255 | 250 | ||
256 | -- Actually stuff ourself into ThingSpace. | ||
257 | modules[_NAME] = {module = _M, name = _NAME, } | ||
258 | setmetatable(_M, {Thing}) | ||
259 | |||
260 | -- This is the final version that we export. Finally we can include the ThingSpace stuff. | ||
261 | moduleBegin = function (name, author, copyright, version, timestamp, skin) | ||
262 | local result = skangModuleBegin(name, author, copyright, version, timestamp, skin) | ||
263 | modules[name] = {module = result, name = name, } | ||
264 | setmetatable(result, Thing) | ||
265 | return result | ||
266 | end | ||
267 | |||
268 | -- Restore the environment. | ||
269 | moduleEnd = function (module) | ||
270 | setfenv(2, module.savedEnvironment) | ||
271 | end | ||
272 | 251 | ||
273 | --[[ TODO - Users might want to use two or more copies of this module. Keep that in mind. local a = require 'test', b = require 'test' might handle that though? | 252 | --[[ TODO - Users might want to use two or more copies of this module. Keep that in mind. local a = require 'test', b = require 'test' might handle that though? |
274 | Not unless skang.thing() knows about a and b, which it wont. | 253 | Not unless skang.thing() knows about a and b, which it wont. |
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index 0c4968d..470fe23 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua | |||
@@ -47,6 +47,6 @@ end | |||
47 | -- Test it. | 47 | -- Test it. |
48 | local skang = require 'skang' | 48 | local skang = require 'skang' |
49 | local test = require 'test' | 49 | local test = require 'test' |
50 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.func.help .. ' ->> ' .. test.action .. ' ' .. skang.things.f.action) | 50 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.func.help .. ' ->> ' .. skang.things.f.action) |
51 | test.func('one', 2) | 51 | test.func('one', 2) |
52 | skang.things.func('seven', 'aight') | 52 | skang.things.func('seven', 'aight') |