diff options
author | David Walter Seikel | 2014-03-29 23:42:54 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-03-29 23:42:54 +1000 |
commit | 075d853a95e07530a9f5437dbbec36a3afe1621f (patch) | |
tree | 18072d511beefc5227261ad0a360834501ba71d9 /ClientHamr/GuiLua/test.lua | |
parent | Add my usual table printer. (diff) | |
download | SledjHamr-075d853a95e07530a9f5437dbbec36a3afe1621f.zip SledjHamr-075d853a95e07530a9f5437dbbec36a3afe1621f.tar.gz SledjHamr-075d853a95e07530a9f5437dbbec36a3afe1621f.tar.bz2 SledjHamr-075d853a95e07530a9f5437dbbec36a3afe1621f.tar.xz |
Rewrite skang.lua to put all the Thing stuff in metatables, plus get(), reset(), and set().
Diffstat (limited to '')
-rw-r--r-- | ClientHamr/GuiLua/test.lua | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index 2f93c94..c983943 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua | |||
@@ -48,22 +48,21 @@ end | |||
48 | local skang = require 'skang' | 48 | local skang = require 'skang' |
49 | local test = require 'test' | 49 | local test = require 'test' |
50 | local test_c = require 'test_c' | 50 | local test_c = require 'test_c' |
51 | local copy_test = skang.new(test, 'copy') | 51 | local copy = skang.copy(test, 'copy') |
52 | 52 | ||
53 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.ffunc.help .. ' ->> ' .. skang.things.f.action) | 53 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.get(test, 'ffunc', 'help') .. ' ->> ' .. skang.get(test, 'f', 'action')) |
54 | print('foo = ' .. test.foo .. ' ->> ' .. skang.things.foo.help) | 54 | print('foo = ' .. test.foo .. ' ->> ' .. skang.get(test, 'foo', 'help')) |
55 | print('cfunc ->> ' .. skang.things.cfunc.help) | 55 | print('cfunc ->> ' .. skang.get(test_c, 'cfunc', 'help')) |
56 | test.ffunc('one', 2) | 56 | test.ffunc('one', 2) |
57 | test_c.cfunc(0, 'zero') | 57 | test_c.cfunc(0, 'zero') |
58 | --skang.things.ffunc('seven', 'aight') | ||
59 | print('') | 58 | print('') |
60 | 59 | ||
61 | test.f = 42 | 60 | test.f = 42 |
62 | print('f is now ' .. test.fooble .. ' ' .. test.f .. ' ' .. skang.things.f.help .. ' ' .. skang.things.fooble.help) | 61 | print('f is now ' .. test.fooble .. ' ' .. test.f) |
63 | print('copy_f is now ' .. copy_test.fooble .. ' ' .. copy_test.f) | 62 | print('copy_f is now ' .. copy.fooble .. ' ' .. copy.f) |
64 | copy_test.f = 24 | 63 | copy.f = 24 |
65 | print('f is now ' .. test.fooble .. ' ' .. test.f .. ' ' .. skang.things.f.help .. ' ' .. skang.things.fooble.help) | 64 | print('f is now ' .. test.fooble .. ' ' .. test.f) |
66 | print('copy_f is now ' .. copy_test.fooble .. ' ' .. copy_test.f) | 65 | print('copy_f is now ' .. copy.fooble .. ' ' .. copy.f) |
67 | test.f = nil | 66 | test.f = nil |
68 | print('f is now ' .. test.fooble .. ' ' .. test.f) | 67 | print('f is now ' .. test.fooble .. ' ' .. test.f) |
69 | test.fooble = 42 | 68 | test.fooble = 42 |
@@ -92,10 +91,9 @@ print(skang.isBoolean(function (a) return false end)) | |||
92 | print('') | 91 | print('') |
93 | 92 | ||
94 | -- Make it required, even though it was anyway. | 93 | -- Make it required, even though it was anyway. |
95 | skang.thing{'f', required = true} | 94 | skang.set(test, 'f', 'required', true) |
96 | -- First, disable the default value, so we see "is required" errors. | 95 | -- Disable the default value, so we see "is required" errors. |
97 | -- Coz using the above syntax means that default is never passed to skang.thing, since it's nil. | 96 | skang.reset(test, 'f', 'default') |
98 | skang.things.f.default = nil | ||
99 | test.fooble = 42 | 97 | test.fooble = 42 |
100 | test.fooble = 'Should fail.' | 98 | test.fooble = 'Should fail.' |
101 | test.fooble = 42 | 99 | test.fooble = 42 |
@@ -105,3 +103,13 @@ test.fooble = 42 | |||
105 | test.fooble = true | 103 | test.fooble = true |
106 | test.f = 42 | 104 | test.f = 42 |
107 | test.f = nil | 105 | test.f = nil |
106 | print('') | ||
107 | |||
108 | skang.set(test, 'f', 'required', false) | ||
109 | test.f = 42 | ||
110 | test.f = nil | ||
111 | skang.set(test, 'f', 'default', 999) | ||
112 | test.f = 42 | ||
113 | test.f = nil | ||
114 | print(test.fooble .. ' ' .. test.f) | ||
115 | print(skang.get(test, 'f', 'default')) | ||