Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local timer = nil;
- function clear()
- term.clear();
- term.setCursorPos(1,1);
- end
- function concat(a,b)
- return tostring(a)..tostring(b);
- end
- function find(str,char)
- local length = str:len(str);
- local i = 1;
- local found = false;
- while i <= length do
- local current_char = str:sub(i,i);
- if current_char == char then
- found = i;
- break;
- end
- i = i + 1;
- end
- return found;
- end
- function explode(str,char)
- if str ~= nil then
- if char == nil then
- char = " ";
- end
- if string.len(char) ~= 1 then
- return false;
- end
- local length = string.len(str);
- if length >= 0 then
- local search = find(str,char);
- local part1 = "";
- local part2 = "";
- if search == false then
- part1 = str;
- else
- part1 = string.sub(str,1,search - 1);
- part2 = string.sub(str,search + 1,length);
- end
- return tostring(part1),tostring(part2);
- end
- end
- return false;
- end
- function split(str,char)
- local array = {};
- if char == nil then
- char = " ";
- end
- while true do
- local part1,part2 = explode(str,char);
- table.insert(array,part1);
- str = part2;
- if part2 == "" then
- break;
- end
- end
- return array;
- end
- function main(call)
- loop(call,0);
- end
- function exit()
- error();
- end
- function loop(call,sec)
- if sec == nil then
- sec = 1;
- end
- local ret = call("init",nil,nil,nil,nil,nil);
- local continue = true;
- local terminate = false;
- if ret == false then
- continue = false;
- end
- while continue do
- if sec ~= 0 then
- if timer == nil then
- timer = os.startTimer(sec);
- end
- end
- local event,v1,v2,v3,v4,v5 = os.pullEventRaw();
- if event == "timer" and v1 == timer then
- timer = nil;
- event = "loop";
- v1 = nil;
- end
- ret = call(event,v1,v2,v3,v4,v5);
- if event == "loop" then
- if ret ~= nil then
- sec = ret;
- end
- elseif event == "terminate" and ret ~= false then
- continue = false;
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment