framework enhancement
- multi modules support in chat command - robust against syntax or runtime errors in module - output in addition to the chat trough new function qa_block.out(...)
This commit is contained in:
parent
baa143d0ec
commit
effb2ed486
@ -78,14 +78,14 @@ for name, def in pairs(minetest.registered_items) do
|
||||
local recipes_for_node = minetest.get_all_craft_recipes(name)
|
||||
if recipes_for_node == nil then
|
||||
if print_no_recipe then
|
||||
print(name, "no_recipe")
|
||||
qa_block.out(name, "no_recipe")
|
||||
end
|
||||
else
|
||||
for kn, vn in ipairs(recipes_for_node) do
|
||||
for ku, vu in ipairs(known_recipes) do
|
||||
if vu.output ~= vn.output and
|
||||
is_same_recipe(vu, vn) == true then
|
||||
print('same recipe', vu.output, vn.output)
|
||||
qa_block.out('same recipe', vu.output, vn.output)
|
||||
-- print (dump(vu),dump(vn)) --debug
|
||||
end
|
||||
end
|
||||
|
89
init.lua
89
init.lua
@ -1,18 +1,64 @@
|
||||
print("initialize Starting QA Block")
|
||||
|
||||
qa_block = {}
|
||||
|
||||
function qa_block.out(...)
|
||||
local outsting = ""
|
||||
local out
|
||||
local x
|
||||
for x, out in ipairs(arg) do
|
||||
print(out)
|
||||
outsting = (outsting..tostring(out)..'\t')
|
||||
end
|
||||
print(outsting)
|
||||
minetest.chat_send_all(outsting)
|
||||
end
|
||||
|
||||
|
||||
local filepath = minetest.get_modpath("qa_block").."/checks/"
|
||||
local defaultmodule = "same_recipe"
|
||||
|
||||
|
||||
local function do_module( module )
|
||||
qa_block.out("QA checks started")
|
||||
--- TODO: some selectoin of executed check
|
||||
local file = filepath..module..".lua"
|
||||
|
||||
local f=io.open(file,"r")
|
||||
if not f then
|
||||
qa_block.out("file "..file.." not found")
|
||||
else
|
||||
io.close(f)
|
||||
local compiled
|
||||
local executed
|
||||
local err
|
||||
local compiled, err = loadfile(file)
|
||||
if not compiled then
|
||||
qa_block.out("syntax error in module file"..file)
|
||||
qa_block.out(err)
|
||||
else
|
||||
executed, err = pcall(compiled)
|
||||
if not executed then
|
||||
qa_block.out("runtime error appears")
|
||||
qa_block.out(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
qa_block.out("QA checks finished")
|
||||
|
||||
end
|
||||
|
||||
local filepath = minetest.get_modpath("qa_block").."/checks/same_recipe.lua"
|
||||
minetest.register_chatcommand("qa_block", {
|
||||
params = "",
|
||||
params = "<checkmodule>",
|
||||
description = "Perform qa block check",
|
||||
privs = {interact = true},
|
||||
func = function()
|
||||
print("QA checks started")
|
||||
|
||||
--- TODO: some selectoin of executed check
|
||||
dofile(filepath)
|
||||
print("QA checks finished. Have a look to the debug.txt")
|
||||
return true, "QA checks finished."
|
||||
func = function(name, param)
|
||||
if param and param ~= "" then
|
||||
do_module(param)
|
||||
else
|
||||
do_module(defaultmodule)
|
||||
end
|
||||
return true, "QA checks finished."
|
||||
end,
|
||||
})
|
||||
|
||||
@ -24,34 +70,11 @@ minetest.register_node("qa_block:block", {
|
||||
})
|
||||
|
||||
|
||||
|
||||
--qa = {}
|
||||
--function qa.list_variables(var,recursive)
|
||||
-------------------------------------------------------------
|
||||
---- dump variables in tables. can be reduced in dump depth
|
||||
---- get all variables in memory
|
||||
---- the top node in LUA is "_G" ;)
|
||||
-- if recursive == nil then
|
||||
-- recursive = false
|
||||
-- end
|
||||
--
|
||||
-- for k,v in pairs(var) do
|
||||
-- print(k,v)
|
||||
--
|
||||
-- if type(v) == "table" and recursive == true then
|
||||
-- qa.dump_variables(v,false, "->")
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
|
||||
minetest.register_on_placenode(function (pos, node)
|
||||
if node.name == "qa_block:block" then
|
||||
print("QA checks started")
|
||||
|
||||
--- TODO: some selectoin of executed check
|
||||
dofile(filepath)
|
||||
print("QA checks finished. Have a look to the debug.txt")
|
||||
do_module(defaultmodule)
|
||||
minetest.env:add_node(pos, {name="air"})
|
||||
end
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user