aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-03-31 22:45:21 +1000
committerDavid Walter Seikel2014-03-31 22:45:21 +1000
commitbd05c036e46f6fbbaa8c79414a48dc02d00e7d33 (patch)
treebd0d349e97147cc4d2a1c6faa1f5a075bb5c9701
parentMore ways to call thing, and rename it thingasm. (diff)
downloadSledjHamr-bd05c036e46f6fbbaa8c79414a48dc02d00e7d33.zip
SledjHamr-bd05c036e46f6fbbaa8c79414a48dc02d00e7d33.tar.gz
SledjHamr-bd05c036e46f6fbbaa8c79414a48dc02d00e7d33.tar.bz2
SledjHamr-bd05c036e46f6fbbaa8c79414a48dc02d00e7d33.tar.xz
Clean up after my thingasm.
-rw-r--r--ClientHamr/GuiLua/skang.lua47
-rw-r--r--ClientHamr/GuiLua/test.lua13
-rw-r--r--ClientHamr/GuiLua/test_c.c48
3 files changed, 48 insertions, 60 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua
index 9e3dfd8..25886c2 100644
--- a/ClientHamr/GuiLua/skang.lua
+++ b/ClientHamr/GuiLua/skang.lua
@@ -206,6 +206,13 @@ csv2table = function (csv)
206end 206end
207 207
208 208
209shiftLeft = function (tab)
210 local result = tab[1]
211 table.remove(tab, 1)
212 return result
213end
214
215
209-- My clever boolean check, this is the third language I've written this in. B-) 216-- My clever boolean check, this is the third language I've written this in. B-)
210-- true 1 yes ack ok one positive absolutely affirmative 'ah ha' 'shit yeah' 'why not' 217-- true 1 yes ack ok one positive absolutely affirmative 'ah ha' 'shit yeah' 'why not'
211local isTrue = 't1aopswy' 218local isTrue = 't1aopswy'
@@ -624,35 +631,22 @@ thingasm = function (names, ...)
624 631
625 -- Check how we were called, and re arrange stuff to match. 632 -- Check how we were called, and re arrange stuff to match.
626 if 0 == #params then 633 if 0 == #params then
627 if ('table' == type(names)) then 634 if ('table' == type(names)) then -- thingasm{...}
628 -- thingasm{...}
629 params = names 635 params = names
630 names = params[1] 636 names = shiftLeft(params)
631 table.remove(params, 1) 637 if 'table' == type(names) then -- thingasm{module, 'foo', ...}
632 if 'table' == type(names) then
633 -- thingasm{module, 'foo', ...}
634 module = names 638 module = names
635 names = params[1] 639 names = shiftLeft(params)
636 table.remove(params, 1)
637 end 640 end
638 else 641 end -- thingasm("foo") otherwise
639 -- thingasm("foo")
640 end
641 else 642 else
642 if 'table' == type(names) then 643 if 'table' == type(names) then
643 module = names 644 module = names
644 if 'string' == type(...) then 645 if 'string' == type(...) then params = {...} -- C or __call(table, string, ..)
645 -- C or __call(table, string, ..) 646 elseif 'table' == type(...) then params = ... -- __call(table, table)
646 params = {...}
647 elseif 'table' == type(...) then
648 -- __call(table, table)
649 params = ...
650 end 647 end
651 names = params[1] 648 names = shiftLeft(params)
652 table.remove(params, 1) 649 end -- thingasm('foo', ...) otherwise
653 else
654 -- thingasm('foo', ...)
655 end
656 end 650 end
657 651
658 -- Break out the names. 652 -- Break out the names.
@@ -683,23 +677,18 @@ thingasm = function (names, ...)
683 end 677 end
684 678
685 local thingy = modThing.__stuff[name] 679 local thingy = modThing.__stuff[name]
686 if not thingy then -- This is a new Thing. 680 if not thingy then -- This is a new Thing.
687 new = true 681 new = true
688 thingy = {} 682 thingy = {}
689 thingy.module = module 683 thingy.module = module
690 thingy.names = names 684 thingy.names = names
691 -- To pick up isValid, pattern, and the other stuff. 685 setmetatable(thingy, {__index = Thing}) -- To pick up isValid, pattern, and the other stuff.
692 setmetatable(thingy, {__index = Thing})
693 end 686 end
694 687
695 -- Pull out positional arguments. 688 -- Pull out positional arguments.
696 thingy.help = params[1] or thingy.help 689 thingy.help = params[1] or thingy.help
697 thingy.default = params[2] or thingy.default 690 thingy.default = params[2] or thingy.default
698 local types = params[3] or table.concat(thingy.types or {}, ',') 691 local types = params[3] or table.concat(thingy.types or {}, ',')
699 thingy.widget = params[4] or thingy.widget
700 thingy.required = params[5] or thingy.required
701 thingy.acl = params[6] or thingy.acl
702 thingy.boss = params[7] or thingy.boss
703 692
704 -- Pull out named arguments. 693 -- Pull out named arguments.
705 for k, v in pairs(params) do 694 for k, v in pairs(params) do
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua
index aebe4ae..34f2bf9 100644
--- a/ClientHamr/GuiLua/test.lua
+++ b/ClientHamr/GuiLua/test.lua
@@ -31,7 +31,7 @@ local fool
31 31
32-- TODO - Could have a table of tables, and ipair through the top level, passing the inner ones to skang.thing{}. 32-- TODO - Could have a table of tables, and ipair through the top level, passing the inner ones to skang.thing{}.
33 33
34skang.thingasm('fooble,f', 'Help text goes here', 1, nil, '"edit", "The fooble:", 1, 1, 10, 50', true) 34skang.thingasm{'fooble,f', 'Help text goes here', 1, widget='"edit", "The fooble:", 1, 1, 10, 50', required=true}
35skang.thingasm('bar', 'Help text', "Default") 35skang.thingasm('bar', 'Help text', "Default")
36skang.thingasm('foo') 36skang.thingasm('foo')
37 37
@@ -54,6 +54,7 @@ local copy = skang.copy(test, 'copy')
54 54
55print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.get(test, 'ffunc', 'help') .. ' ->> ' .. skang.get(test, 'f', 'action')) 55print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.get(test, 'ffunc', 'help') .. ' ->> ' .. skang.get(test, 'f', 'action'))
56print('foo = ' .. test.foo .. ' ->> ' .. skang.get(test, 'foo', 'help')) 56print('foo = ' .. test.foo .. ' ->> ' .. skang.get(test, 'foo', 'help'))
57print('cfooble = ' .. test_c.cfooble .. ' ->> ' .. skang.get(test_c, 'cfooble', 'help') .. '[' .. skang.get(test_c, 'cfooble', 'widget') .. ']')
57print('cfunc ->> ' .. skang.get(test_c, 'cfunc', 'help')) 58print('cfunc ->> ' .. skang.get(test_c, 'cfunc', 'help'))
58test.ffunc('one', 2) 59test.ffunc('one', 2)
59test_c.cfunc(0, 'zero') 60test_c.cfunc(0, 'zero')
@@ -120,10 +121,10 @@ print('')
120local stuff = {} 121local stuff = {}
121stuff.t = {} 122stuff.t = {}
122 123
123skang.thingasm{stuff, 'a', help = 'A test stufflet'} 124skang.thingasm{stuff, 'a', 'A test stufflet'}
124skang.thingasm{stuff.t, 'b', help = 'A sub stufflet'} 125skang.thingasm{stuff.t, 'b', 'A sub stufflet'}
125skang.thingasm{stuff.t, 'c', help = 'Another sub stufflet'} 126skang.thingasm{stuff.t, 'c', 'Another sub stufflet'}
126skang.thingasm{stuff, 's', help = 'A Stuff', types='table'} 127skang.thingasm{stuff, 's', 'A Stuff', types='table'}
127stuff.s{'sa,a', help = 'A stufflet in a Stuff'} 128stuff.s{'sa,a', help = 'A stufflet in a Stuff'}
128stuff.s{'sb,b', help = 'Another stufflet in a Stuff'} 129stuff.s{'sb,b', help = 'Another stufflet in a Stuff'}
129 130
@@ -141,7 +142,7 @@ print(skang.get(stuff.t, 'c', 'help'))
141print(skang.get(stuff, 's', 'help')) 142print(skang.get(stuff, 's', 'help'))
142print(skang.get(stuff.s, 'sa', 'help')) 143print(skang.get(stuff.s, 'sa', 'help'))
143print(skang.get(stuff.s, 'sb', 'help')) 144print(skang.get(stuff.s, 'sb', 'help'))
144skang.thingasm{test, 'baz,b', help = 'A test stufflet for test'} 145skang.thingasm{test, 'baz,b', 'A test stufflet for test'}
145print(skang.get(test, 'b', 'help')) 146print(skang.get(test, 'b', 'help'))
146print(skang.get(test, 'f', 'help')) 147print(skang.get(test, 'f', 'help'))
147--skang.printTableStart(getmetatable(stuff.s), '', 'stuff.s metatable') 148--skang.printTableStart(getmetatable(stuff.s), '', 'stuff.s metatable')
diff --git a/ClientHamr/GuiLua/test_c.c b/ClientHamr/GuiLua/test_c.c
index 10af91c..8f6ee7b 100644
--- a/ClientHamr/GuiLua/test_c.c
+++ b/ClientHamr/GuiLua/test_c.c
@@ -65,6 +65,7 @@ returned, but we want to do something different with skang.
65*/ 65*/
66int luaopen_test_c(lua_State *L) 66int luaopen_test_c(lua_State *L)
67{ 67{
68 lua_Number i;
68 69
69 // In theory, the only thing on the stack now is 'test_c' from the require() call. 70 // In theory, the only thing on the stack now is 'test_c' from the require() call.
70 71
@@ -121,16 +122,29 @@ int luaopen_test_c(lua_State *L)
121 122
122// skang.thing('cfooble,c', 'Help text goes here', 1, 'number', \"'edit', 'The fooble:', 1, 1, 10, 50\", true) 123// skang.thing('cfooble,c', 'Help text goes here', 1, 'number', \"'edit', 'The fooble:', 1, 1, 10, 50\", true)
123 lua_getfield(L, skang, "thingasm"); 124 lua_getfield(L, skang, "thingasm");
125 i = 1;
126 lua_newtable(L);
127 lua_pushnumber(L, i++);
124 lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment. 128 lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment.
129 lua_settable(L, -3);
130
131 lua_pushnumber(L, i++);
125 lua_pushstring(L, "cfooble,c"); 132 lua_pushstring(L, "cfooble,c");
126 lua_pushstring(L, "Help text"); 133 lua_settable(L, -3);
134
135 lua_pushnumber(L, i++);
136 lua_pushstring(L, "cfooble help text");
137 lua_settable(L, -3);
138
139 lua_pushnumber(L, i++);
127 lua_pushnumber(L, 1); 140 lua_pushnumber(L, 1);
128 lua_pushnil(L); 141 lua_settable(L, -3);
142
129 lua_pushstring(L, "'edit', 'The cfooble:', 1, 1, 10, 50"); 143 lua_pushstring(L, "'edit', 'The cfooble:', 1, 1, 10, 50");
144 lua_setfield(L, -2, "widget");
130 lua_pushboolean(L, 1); // Is required. 145 lua_pushboolean(L, 1); // Is required.
131 lua_pushnil(L); // Default ACL. 146 lua_setfield(L, -2, "required");
132 lua_pushnil(L); // No boss. 147 lua_call(L, 1, 0);
133 lua_call(L, 9, 0);
134 148
135// skang.thing('cbar', 'Help text', 'Default') 149// skang.thing('cbar', 'Help text', 'Default')
136 lua_getfield(L, skang, "thingasm"); 150 lua_getfield(L, skang, "thingasm");
@@ -138,25 +152,13 @@ int luaopen_test_c(lua_State *L)
138 lua_pushstring(L, "cbar"); 152 lua_pushstring(L, "cbar");
139 lua_pushstring(L, "Help text"); 153 lua_pushstring(L, "Help text");
140 lua_pushstring(L, "Default"); 154 lua_pushstring(L, "Default");
141 lua_pushnil(L); // No type. 155 lua_call(L, 4, 0);
142 lua_pushnil(L); // No widget.
143 lua_pushnil(L); // Not required.
144 lua_pushnil(L); // Default ACL.
145 lua_pushnil(L); // No boss.
146 lua_call(L, 9, 0);
147 156
148// skang.thing('cfoo') 157// skang.thing('cfoo')
149 lua_getfield(L, skang, "thingasm"); 158 lua_getfield(L, skang, "thingasm");
150 lua_pushstring(L, "cfoo");
151 lua_pushnil(L); // No help.
152 lua_pushnil(L); // No default.
153 lua_pushnil(L); // No type.
154 lua_pushnil(L); // No widget.
155 lua_pushnil(L); // Not required.
156 lua_pushnil(L); // Default ACL.
157 lua_pushnil(L); // No boss.
158 lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment. 159 lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment.
159 lua_call(L, 9, 0); 160 lua_pushstring(L, "cfoo");
161 lua_call(L, 2, 0);
160 162
161// skang.thing('cfunc', 'Help Text', ffunc, 'number,string') 163// skang.thing('cfunc', 'Help Text', ffunc, 'number,string')
162 lua_getfield(L, skang, "thingasm"); 164 lua_getfield(L, skang, "thingasm");
@@ -165,11 +167,7 @@ int luaopen_test_c(lua_State *L)
165 lua_pushstring(L, "cfunc does nothing really"); 167 lua_pushstring(L, "cfunc does nothing really");
166 lua_pushcfunction(L, cfunc); 168 lua_pushcfunction(L, cfunc);
167 lua_pushstring(L, "number,string"); 169 lua_pushstring(L, "number,string");
168 lua_pushnil(L); // No widget. 170 lua_call(L, 5, 0);
169 lua_pushnil(L); // Not required.
170 lua_pushnil(L); // Default ACL.
171 lua_pushnil(L); // No boss.
172 lua_call(L, 9, 0);
173 171
174// skang.moduleEnd(_M) 172// skang.moduleEnd(_M)
175 lua_getfield(L, skang, "moduleEnd"); 173 lua_getfield(L, skang, "moduleEnd");