Add meta prune to close all unoperated nodes

- Add informations and help in meta command for the prune subcommand
 - Add `metatools.prune` to prune from the API
This commit is contained in:
LeMagnesium 2016-09-19 19:03:49 +02:00
parent cff85689d7
commit 0dfec122fe
No known key found for this signature in database
GPG Key ID: A54DDB5272C51E8B

View File

@ -124,7 +124,6 @@ function meta_exec(struct)
if struct.required then
-- will call meta_assertion from here
for category, req in pairs(struct.required) do
minetest.log("Matching " .. category)
if category == "position" and not assert_pos(req) then
return false, ("- %s - Failure : Invalid position : %s"):format(struct.scope, dump_normalize(req))
@ -185,7 +184,6 @@ function meta_exec(struct)
return false, ("- %s - Failure : Invalid mode, %s is required"):format(struct.scope, dump_normalize(req.mode))
end
end
minetest.log(("Match %s succeeded"):format(category))
end
end
@ -317,6 +315,15 @@ function metatools.purge(contextid)
end
end
function metatools.prune()
for id, ctx in pairs(contexts) do
if not metatools.get_context_owner(id) then
metatools.close_node(id)
end
end
return true, "contexts pruned"
end
function metatools.list_init(contextid, listname, size)
if not listname or listname == "" then
return false, "missing or empty list name"
@ -467,6 +474,7 @@ minetest.register_chatcommand("meta", {
"- meta::help - /meta select <contextid> : Select the node with context <contextid> for operations\n"..
"- meta::help - /meta switch : Switch open mode in the current context\n" ..
"- meta::help - /meta close : Close the currently selected node\n" ..
"- meta::help - /meta prune : Close all currently unoperated nodes\n" ..
"- meta::help - /meta show : Show you the fields/lists available\n" ..
"- meta::help - /meta set <name> <value> : Set variable 'name' to 'value', overriding any existing data\n" ..
"- meta::help - /meta unset <name> : Set variable 'name' to nil, ignoring whether it exists or not\n" ..
@ -546,6 +554,14 @@ minetest.register_chatcommand("meta", {
}
})
-- meta prune
elseif params[1] == "prune" then
return meta_exec({
scope = "meta::prune",
func = metatools.prune,
params = {},
})
-- meta switch
elseif params[1] == "switch" then
return meta_exec({