From 2ef924b06e301946e0ffcc6d4187c708d5366a73 Mon Sep 17 00:00:00 2001 From: AiTechEye <40591179+AiTechEye@users.noreply.github.com> Date: Wed, 16 Jan 2019 10:26:32 +0100 Subject: [PATCH] fix runaway loop --- api.lua | 19 ++++++++++++++++++- functions.lua | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api.lua b/api.lua index 665c4ac..ec8179c 100644 --- a/api.lua +++ b/api.lua @@ -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("%)"," } ") diff --git a/functions.lua b/functions.lua index 13704f5..4f9457b 100644 --- a/functions.lua +++ b/functions.lua @@ -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