check script bugfixes

This commit is contained in:
Joachim Stolberg 2020-06-18 21:10:39 +02:00
parent 0f1ae64fee
commit 7a0974ee3f
5 changed files with 28 additions and 4 deletions

View File

@ -279,6 +279,9 @@ signs_bot.register_botcommand("pause", {
mem.steps = nil
return signs_bot.DONE
end
if mem.capa then
mem.capa = mem.capa + 1
end
return signs_bot.BUSY
end,
})
@ -289,6 +292,9 @@ signs_bot.register_botcommand("stop", {
num_param = 0,
description = I("Stop the robot."),
cmnd = function(base_pos, mem, slot)
if mem.capa then
mem.capa = mem.capa + 2
end
return signs_bot.DONE
end,
})

View File

@ -203,7 +203,7 @@ signs_bot.register_botcommand("place_above", {
local function dig_item(base_pos, robot_pos, param2, slot, route, level)
local pos1 = lib.dest_pos(robot_pos, param2, route)
pos1.y = pos1.y + level
pos1.y = pos1.y + (level or 0)
local node = lib.get_node_lvm(pos1)
local dug_name = lib.is_simple_node(node)
if not lib.not_protected(base_pos, pos1) then

View File

@ -233,6 +233,8 @@ local function move(mem, any_sensor)
activate_sensor(mem.robot_pos, (mem.robot_param2 + 1) % 4)
activate_sensor(mem.robot_pos, (mem.robot_param2 + 3) % 4)
end
elseif mem.capa then
mem.capa = mem.capa + 1
end
end

View File

@ -95,6 +95,7 @@ end
local function pass1(tokens)
local pc = 1
tSymbolTbl = {}
for _, token in ipairs(tokens) do
if token:find("%w+:") then
tSymbolTbl[token] = pc
@ -129,6 +130,9 @@ end
-- Commands
-------------------------------------------------------------------------------
local function register_command(cmnd_name, num_param, cmnd_func, check_func)
assert(num_param, cmnd_name..": num_param = "..dump(num_param))
assert(cmnd_func, cmnd_name..": cmnd_func = "..dump(cmnd_func))
assert(check_func or num_param == 0, cmnd_name..": check_func = "..dump(check_func))
lCmdLookup[#lCmdLookup + 1] = {num_param, cmnd_func, cmnd_name}
tCmdDef[cmnd_name] = {
num_param = num_param,
@ -174,6 +178,9 @@ register_command("call", 1,
mem.Stack[#mem.Stack + 1] = mem.pc + 2
mem.pc = addr - 2
return api.DONE
end,
function(addr)
return tSymbolTbl[addr..":"]
end
)
@ -192,6 +199,9 @@ register_command("jump", 1,
function(base_pos, mem, addr)
mem.pc = addr - 2
return api.DONE
end,
function(addr)
return tSymbolTbl[addr..":"]
end
)
@ -205,14 +215,19 @@ register_command("exit", 0,
-- API functions
-------------------------------------------------------------------------------
function api.register_command(cmnd_name, num_param, cmnd_func)
register_command(cmnd_name, num_param, cmnd_func)
function api.register_command(cmnd_name, num_param, cmnd_func, check_func)
register_command(cmnd_name, num_param, cmnd_func, check_func)
end
-- function returns: true/false, error_string, line-num
function api.check_script(script)
local tbl = {}
local num_token = 0
-- to fill the symbol table
local tokens = tokenizer(script)
pass1(tokens)
for idx, cmnd, param1, param2, param3 in get_line_tokens(script) do
if tCmdDef[cmnd] then
num_token = num_token + 1 + tCmdDef[cmnd].num_param
@ -222,7 +237,7 @@ function api.check_script(script)
param1 = tonumber(param1) or param1
param2 = tonumber(param2) or param2
param3 = tonumber(param3) or param3
if tCmdDef[cmnd].check and not tCmdDef[cmnd].check(param1, param2, param3) then
if tCmdDef[cmnd].num_param > 0 and not tCmdDef[cmnd].check(param1, param2, param3) then
return false, I("Parameter error"), idx
end
elseif not cmnd:find("%w+:") then

View File

@ -141,6 +141,7 @@ end
-- Check rights before node is dug or inventory is used
function signs_bot.lib.not_protected(base_pos, pos)
local me = M(base_pos):get_string("owner")
minetest.load_area(pos)
if minetest.is_protected(pos, me) then
return false
end