aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-03-22 15:48:05 +1000
committerDavid Walter Seikel2014-03-22 15:48:05 +1000
commit840a7c106b0f52794d4c170f462bfd5908f3fa60 (patch)
tree347138a338fb37391db6fb81778719825e813f92 /ClientHamr
parentDissolve ThingSpace, and commands & parameters. (diff)
downloadSledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.zip
SledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.tar.gz
SledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.tar.bz2
SledjHamr-840a7c106b0f52794d4c170f462bfd5908f3fa60.tar.xz
Remove the excess moduleBegin crap.
Diffstat (limited to 'ClientHamr')
-rw-r--r--ClientHamr/GuiLua/skang.lua39
-rw-r--r--ClientHamr/GuiLua/test.lua2
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".
59do -- Only I'm not gonna indent this. 59do -- 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(). 61moduleBegin = function (name, author, copyright, version, timestamp, skin)
62local 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
110end 109end
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.
113local smb = function (name, author, copyright, version, timestamp, skin) 112local _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
116end
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.
119local _M = smb('skang', 'David Seikel', '2014', '0.0', '2014-03-19 19:01:00') 115moduleEnd = function (module)
116 setfenv(2, module.savedEnvironment)
117end
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 -
181things = {} 178things = {}
182modules = {}
183
184 179
185Thing = 180Thing =
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.
257modules[_NAME] = {module = _M, name = _NAME, }
258setmetatable(_M, {Thing})
259
260-- This is the final version that we export. Finally we can include the ThingSpace stuff.
261moduleBegin = 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
266end
267
268-- Restore the environment.
269moduleEnd = function (module)
270 setfenv(2, module.savedEnvironment)
271end
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.
48local skang = require 'skang' 48local skang = require 'skang'
49local test = require 'test' 49local test = require 'test'
50print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.func.help .. ' ->> ' .. test.action .. ' ' .. skang.things.f.action) 50print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.func.help .. ' ->> ' .. skang.things.f.action)
51test.func('one', 2) 51test.func('one', 2)
52skang.things.func('seven', 'aight') 52skang.things.func('seven', 'aight')