Implement batch register
Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
parent
e8ec24dacc
commit
253e04ff5d
2 changed files with 20 additions and 1 deletions
7
bc.lua
7
bc.lua
|
|
@ -129,7 +129,12 @@ function BaseControl:register(name, value)
|
||||||
error("can't register \""..name.."\" after finalizing")
|
error("can't register \""..name.."\" after finalizing")
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(value) == "function" then
|
if type(name) == "table" then
|
||||||
|
-- Batch register
|
||||||
|
for name, value in pairs(name) do
|
||||||
|
self:register(name, value)
|
||||||
|
end
|
||||||
|
elseif type(value) == "function" then
|
||||||
if self.local_verbs[name] ~= nil then
|
if self.local_verbs[name] ~= nil then
|
||||||
error("\""..name.."\" already registered")
|
error("\""..name.."\" already registered")
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,20 @@ function test_register()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_register_batch()
|
||||||
|
local bc = BaseControl:new()
|
||||||
|
bc:register{
|
||||||
|
rb1=1234,
|
||||||
|
rb2=4321,
|
||||||
|
rb3v=function() end,
|
||||||
|
}
|
||||||
|
bc:finalize()
|
||||||
|
|
||||||
|
assert_true(bc:has_noun("rb1"))
|
||||||
|
assert_true(bc:has_noun("rb2"))
|
||||||
|
assert_true(bc:has_verb("rb3v"))
|
||||||
|
end
|
||||||
|
|
||||||
function test_available()
|
function test_available()
|
||||||
local bc = BaseControl:new()
|
local bc = BaseControl:new()
|
||||||
bc:register("available1", 1234)
|
bc:register("available1", 1234)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue