fix runaway loop

master
AiTechEye 2019-01-16 10:26:32 +01:00 committed by GitHub
parent bc40b81f48
commit 2ef924b06e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

19
api.lua
View File

@ -54,9 +54,26 @@ end
was.compiler=function(input_text,def)
def=def or{}
if type(input_text)~="string" or input_text:len()<2 or type(def.user)~="string" or not was.is_pos(def.pos) then
if type(input_text)~="string" or input_text:len()<2 or type(def.user)~="string" or not was.is_pos(def.pos) or not def.type then
return
end
if def.type=="node" then
local meta=minetest.get_meta(def.pos)
local t=meta:get_int("was.compiler_last_run")
local runs=meta:get_int("was.compiler_runs")
local sec=was.time("sec",t)
if sec<1 then
meta:set_int("was.compiler_runs",runs+1)
if runs>10 then
return
end
elseif sec>1 then
meta:set_int("was.compiler_runs",1)
meta:set_int("was.compiler_last_run", was.time("gettime"))
end
end
input_text=input_text .."\n"
input_text=input_text:gsub("%("," { ")
input_text=input_text:gsub("%)"," } ")

View File

@ -1,3 +1,18 @@
was.time=function(a,c)
if a=="gettime" then
return os.time()
elseif a=="sec" and was.is_number(c) then
return os.difftime(os.time(), c)
elseif a=="min" and was.is_number(c) then
return os.difftime(os.time(), c) / 60
elseif a=="hour" and was.is_number(c) then
return os.difftime(os.time(), c) / (60 * 60)
elseif a=="day" and was.is_number(c) then
return os.difftime(os.time(), c) / (24 * 60 * 60)
end
end
was.runcmd=function(cmd,name,param)
local c=minetest.registered_chatcommands[cmd]
if not c then