diff options
Diffstat (limited to '')
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 4f221a0..2957fcc 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -200,12 +200,21 @@ TODO - Finish supporting all of the above. | |||
200 | arg1=value1&arg2=value2 For URLs. | 200 | arg1=value1&arg2=value2 For URLs. |
201 | arg1=value1|arg2=value2 Can't remember why, probably the old skang multivalue syntax. | 201 | arg1=value1|arg2=value2 Can't remember why, probably the old skang multivalue syntax. |
202 | Test it all. | 202 | Test it all. |
203 | Skang command line should have standardish stuff, like --version, --help, --help module.thing. | ||
204 | Lua does these already, might be no need to do them ourselves - | ||
205 | -e 'some code'. | ||
206 | -i go interactive after running the script. | ||
207 | -v version. | ||
208 | - read from stdin non interactively. | ||
209 | LuaJIT also has this - | ||
210 | -- stop processing options. | ||
203 | ]] | 211 | ]] |
204 | 212 | ||
205 | ARGS = {} | 213 | ARGS = {} |
206 | lua = '' | 214 | lua = '' |
207 | command = '' | 215 | command = '' |
208 | 216 | ||
217 | |||
209 | -- Do an initial scan and tokenise of the command line arguments. | 218 | -- Do an initial scan and tokenise of the command line arguments. |
210 | scanArguments = function (args) | 219 | scanArguments = function (args) |
211 | if args then | 220 | if args then |
@@ -258,6 +267,21 @@ parseType = function (module, thingy, v, value) | |||
258 | end | 267 | end |
259 | end | 268 | end |
260 | 269 | ||
270 | if 'function' == thingy.types[1] then | ||
271 | local args = {} | ||
272 | -- TODO - Should allow more than one argument, but would need to pass in ARGS and i. | ||
273 | if 2 == #thingy.types then | ||
274 | if value then | ||
275 | -- TODO - Should check the type of the arguments. | ||
276 | args[#args + 1] = value[2] | ||
277 | module[v[2] ](args[1]) | ||
278 | value[2] = nil -- Mark it as used. | ||
279 | else | ||
280 | print('ERROR - Expected an argument for ' .. thingy.names[1]) | ||
281 | end | ||
282 | else | ||
283 | module[v[2] ]() | ||
284 | end | ||
261 | if 'boolean' == thingy.types[1] then | 285 | if 'boolean' == thingy.types[1] then |
262 | if value then | 286 | if value then |
263 | -- Only parse the next value as a boolean if it doesn't have an introducer. | 287 | -- Only parse the next value as a boolean if it doesn't have an introducer. |
@@ -273,15 +297,7 @@ parseType = function (module, thingy, v, value) | |||
273 | end | 297 | end |
274 | end | 298 | end |
275 | 299 | ||
276 | -- Restore the environment, and grab paramateres from standard places. | 300 | pullArguments = function (module) |
277 | moduleEnd = function (module) | ||
278 | -- See if there is a properties file, and run it in the modules environment. | ||
279 | local properties = loadfile(module._NAME .. '.properties') | ||
280 | if properties then | ||
281 | setfenv(properties, getfenv(2)) | ||
282 | properties() | ||
283 | end | ||
284 | |||
285 | -- Look for our command line arguments. | 301 | -- Look for our command line arguments. |
286 | local metaMum = getmetatable(module) | 302 | local metaMum = getmetatable(module) |
287 | if metaMum and metaMum.__self then | 303 | if metaMum and metaMum.__self then |
@@ -318,7 +334,18 @@ moduleEnd = function (module) | |||
318 | end | 334 | end |
319 | end | 335 | end |
320 | end | 336 | end |
337 | end | ||
321 | 338 | ||
339 | -- Restore the environment, and grab paramateres from standard places. | ||
340 | moduleEnd = function (module) | ||
341 | -- See if there is a properties file, and run it in the modules environment. | ||
342 | local properties = loadfile(module._NAME .. '.properties') | ||
343 | if properties then | ||
344 | setfenv(properties, getfenv(2)) | ||
345 | properties() | ||
346 | end | ||
347 | |||
348 | pullArguments(module) | ||
322 | if module.isLua then setfenv(2, module.savedEnvironment) end | 349 | if module.isLua then setfenv(2, module.savedEnvironment) end |
323 | end | 350 | end |
324 | 351 | ||
@@ -529,14 +556,6 @@ TODO - | |||
529 | Maybe try looking in the skang table for Things that are not found? | 556 | Maybe try looking in the skang table for Things that are not found? |
530 | Maybe put Things in the skang table that are unique from modules? | 557 | Maybe put Things in the skang table that are unique from modules? |
531 | I think this is what matrix-RAD Collisions was all about. | 558 | I think this is what matrix-RAD Collisions was all about. |
532 | Skang command line should have standardish stuff, like --version, --help, --help module.thing. | ||
533 | Lua does these already, might be no need to do them ourselves - | ||
534 | -e 'some code'. | ||
535 | -i go interactive after running the script. | ||
536 | -v version. | ||
537 | - read from stdin non interactively. | ||
538 | LuaJIT has this - | ||
539 | -- stop processing options. | ||
540 | ]] | 559 | ]] |
541 | 560 | ||
542 | -- There is no ThingSpace, or Stuff, now it's all just in this meta table. | 561 | -- There is no ThingSpace, or Stuff, now it's all just in this meta table. |
@@ -949,6 +968,7 @@ end | |||
949 | 968 | ||
950 | module = function (name) | 969 | module = function (name) |
951 | end | 970 | end |
971 | |||
952 | skang = function (name) | 972 | skang = function (name) |
953 | end | 973 | end |
954 | quit = function () | 974 | quit = function () |