Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rawsetCursorPos = term.setCursorPos;
- local rawTermWrite = term.write;
- local rawPrint = print;
- local rawsetTextColor = term.setTextColor;
- local rawsetBackgroundColor = term.setBackgroundColor;
- local rawSleep = sleep;
- local rawWrite = write;
- local ioWrite = io.write;
- local rawTermClear = term.clear;
- local t = 1;
- local memory = {};
- term.setCursorPos = function(...)
- memory[t] = {rawsetCursorPos, ...}
- t = t + 1;
- return rawsetCursorPos(...);
- end;
- term.setTextColor = function(...)
- memory[t] = {rawsetTextColor, ...};
- t = t + 1;
- return rawsetTextColor(...);
- end;
- if not rawyield then
- rawyield = coroutine.yield;
- end;
- local clock = os.clock;
- local ndt = clock();
- coroutine.yield = function(...)
- local dt = clock();
- local ret = {rawyield(...)};
- dt = clock()-dt;
- f dt-ndt > .01 and dt > .04 then
- memory[t] = {rawSleep, dt};
- t = t + 1;
- end; ndt = dt;
- return unpack(ret);
- end;
- if not rawpullEvent then
- rawpullEvent = os.pullEvent;
- end;
- os.pullEvent = function(...)
- local dt = clock();
- local ret = {rawpullEvent(...)};
- dt = clock()-dt;
- if ndt-dt > .01 and dt > .04 then
- memory[t] = {rawSleep, dt};
- t = t + 1;
- end; ndt = dt;
- return unpack(ret);
- end;
- term.clear = function()
- memory[t] = {rawTermClear};
- t = t + 1;
- rawTermClear();
- end;
- term.setBackgroundColor = function(...)
- memory[t] = {rawsetBackgroundColor, ...}
- t = t + 1;
- return rawsetBackgroundColor(...);
- end;
- term.write = function(...)
- memory[t] = {rawTermWrite, ...};
- t = t + 1;
- return rawTermWrite(...);
- end;
- write = function(...)
- memory[t] = {rawWrite, ...};
- t = t + 1;
- return rawWrite(...);
- end;
- print = function(...)
- memory[t] = {rawPrint, ...};
- t = t + 1;
- return rawPrint(...);
- end;
- io.write = function(...)
- memory[t] = {ioWrite, ...};
- t = t + 1;
- return ioWrite(...);
- end;
- sleep = function(x)
- if clock()-ndt > .04 then
- memory[t] = {rawSleep, x};
- t = t + 1;
- end;
- return rawSleep(x);
- end;
- local opcode = {
- [rawPrint] = 'print(';
- [rawsetCursorPos] = 'term.setCursorPos(';
- [rawsetTextColor] = 'term.setTextColor(';
- [rawsetBackgroundColor] = 'q(';
- [rawSleep] = 'sleep(';
- [rawWrite] = 'write(';
- [rawTermWrite] = 'term.write(';
- [ioWrite] = 'io.write(';
- [rawyield] = 'sleep(';
- [rawTermClear] = 'term.clear(';
- [rawpullEvent] = 'sleep(';
- };
- term.setBackgroundColour = term.setBackgroundColor;
- term.setTextColour = term.setTextColor;
- local opcode2 = {
- [rawPrint] = true;
- [rawWrite] = true;
- [rawTermWrite] = true;
- [ioWrite] = true;
- };
- local declarations = "q=term.setBackgroundColor; w=term.setTextColor; e=term.setCursorPos; r=term.write; t=write; y=io.write; u=print; i=sleep; o=coroutine.yield; p=term.clear; a=os.pullEvent; "
- local encode = function(recorded, file)
- local file = fs.open(file, 'w');
- file.write(declarations);
- for i = 1,#recorded do
- local piece = recorded[i];
- local cmd = piece[1];
- local line = opcode[cmd];
- local op = (opcode2[cmd] and '[=[') or '';
- local op2 = (opcode2[cmd] and ']=]') or '';
- for i = 2,#piece-1 do
- line = line..op..tostring(piece[i])..op2..', ';
- end;
- if #piece > 1 then
- line = line..op..tostring(piece[#piece])..op2..');\n';
- else
- line = line..'); ';
- end;
- file.write(line);
- end;
- file.close();
- end;
- local args = { ... };
- if #args < 2 then
- print("usage : record -program -output");
- error();
- end;
- shell.run(args[1]);
- encode(memory, args[2]);
- term.setBackgroundColor = rawsetBackgroundColor;
- term.setTextColor = rawsetTextColor;
- term.write = rawTermWrite;
- write = rawWrite;
- io.write = ioWrite;
- print = rawPrint;
- term.setCursorPos = rawsetCursorPos;
- sleep = rawsleep;
- coroutine.yield = rawyield;
- os.pullEvent = rawpullEvent;
- paintutils.drawBox = rawDrawBox;
- paintutils.drawPixel = rawDrawPixel;
- paintutils.drawLine = rawDrawLine;
- paintutils.drawFilledBox = rawDrawFilledBox;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement