Advertisement
Guest User

Text Calculator 1.9.1

a guest
Feb 9th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.51 KB | None | 0 0
  1. --------------------------
  2. --Dubs's Text Calculator--
  3. ------Version: 1.9.1------
  4. --------------------------
  5. --[[notes
  6. lua function
  7. ]]--
  8. --options
  9. local usecolor = true
  10. local docutscenes = true
  11. local autoclear = false
  12. local autoclearinterval = 20
  13. local cutsceneinterval = 0.25
  14. local using_touchlua_app = true
  15. local createfiles = true
  16. --code
  17. require "draw"
  18. function print2(input)
  19.     io.write(input.."\n")
  20. end
  21. function print(input)
  22.     if input==nil then input="" end
  23.     if input==true then input="true" end
  24.     if input==false then input="false" end
  25.     local file=io.open("calculator logs.txt","a+")
  26.     if file:read()=="" then file:write(input)
  27. else do file:write("\n"..input) end end
  28.     file:close()
  29.     print2(input)
  30. end
  31. function clearlog()
  32.     file=io.open("calculator logs.txt","w")
  33.     file:write()
  34.     file:close()
  35. end
  36. crashcount=0
  37. local match="[1234567890/-*^+().#%%]"
  38. local notmatch=[=[[qwertyuiopasdfghjklzxcvbnm:;$&@?!'"{}_\|~<>€£¥]]=]
  39. local x=0
  40. if using_touchlua_app and docutscenes then cutsceneinterval=cutsceneinterval*1000 end
  41. if not io.open("calculator logs.txt","r") and createfiles then
  42.    file=io.open("calculator memory.txt","w")
  43.    file:close()
  44. end
  45. if not io.open("calculator memory.txt","r") and createfiles then
  46.    file=io.open("calculator memory.txt","w")
  47.    file:write("-----------------\nCalculator Recall\n-----------------\n")
  48.    file:close()
  49. end
  50. ::cls::
  51. os.execute("cls") clearlog()
  52. prev=nil
  53. function callable(f)
  54.    return function(...)
  55.        error, result = pcall(f, ...)
  56.        if error then
  57.            return true
  58.        else
  59.            return false
  60.        end
  61.    end
  62. end
  63. function get(getFile)
  64.    local file=io.open(getFile,"r")
  65.    local getOut=file:read("*a")
  66.    file:close()
  67.    print("[[[start get]]]")
  68.    print()
  69.    print(getOut)
  70.    print()
  71.    print("[[[end get]]]")
  72. end
  73. function slowprint(text,delay)
  74.    delay=delay or 125
  75.    for x=1,string.len(text) do
  76.        char=string.sub(text,x,x)
  77.        io.write(char)
  78.        sleep(delay)
  79.    end
  80. end
  81. function factorial(n)
  82.    n=tonumber(n)
  83.    return n > 0 and n * factorial(n-1) or 1
  84. end
  85. function percent(perc,tot)
  86.    return (perc/100)*tot
  87. end
  88. function ee(zero,to)
  89.    return zero*(10^to)
  90. end
  91. function simplify(calcin)
  92.    a,b=calcin:match"(.+)/(.+)"u,v=a,b while v+0>0 do t=u u=v v=t%v end
  93.    return a+0==a/u and a.."/"..b or a/u.."/"..b/u
  94. end
  95. function split(inputstr, sep)
  96.    if sep == nil then
  97.        sep = "%%"
  98.    end
  99.    local t={} ; i=1
  100.    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  101.        t[i] = str
  102.        i = i + 1
  103.    end
  104.    return t
  105. end
  106. function IsPrime(n)
  107.    for i = 2, n^(1/2) do
  108.        if (n % i) == 0 then
  109.            return false
  110.        end
  111.    end
  112.    return true
  113. end
  114. function GetFileSize( filename )
  115.    local fp = io.open( filename )
  116.    if fp == nil then
  117.        return nil
  118.    end
  119.    local filesize = fp:seek( "end" )
  120.    fp:close()
  121.    return filesize
  122. end
  123. function PrimeDecomp( n )
  124.    local f = {}
  125.    if IsPrime( n ) then
  126.        f[1] = n
  127.        return f
  128.    end
  129.    local i = 2
  130.    repeat
  131.        while n % i == 0 do
  132.            f[#f+1] = i
  133.            n = n / i
  134.        end
  135.        repeat
  136.            i = i + 1
  137.        until IsPrime( i )
  138.    until n == 1
  139.    return f
  140. end
  141. function Factors( n )
  142.    local f = {}
  143.    for i = 1, n/2 do
  144.        if n % i == 0 then
  145.            f[#f+1] = i
  146.        end
  147.    end
  148.    f[#f+1] = n
  149.    return f
  150. end
  151. if not using_touchlua_app or not callable(sleep) then
  152.    local clock = os.clock
  153.    function sleep(n)  -- seconds
  154.        local t0 = clock()
  155.        while clock() - t0 <= n do end
  156.    end
  157. end
  158. function print_r ( t )
  159.    local print_r_cache={}
  160.    local function sub_print_r(t,indent)
  161.        if (print_r_cache[tostring(t)]) then
  162.            print(indent.."*"..tostring(t))
  163.        else
  164.            print_r_cache[tostring(t)]=true
  165.            if (type(t)=="table") then
  166.                for pos,val in pairs(t) do
  167.                    if (type(val)=="table") then
  168.                        print(indent.."["..pos.."] => "..tostring(t).." {")
  169.                        sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
  170.                        print(indent..string.rep(" ",string.len(pos)+6).."}")
  171.                    else
  172.                        print(indent.."["..pos.."] => "..tostring(val))
  173.                    end
  174.                end
  175.            else
  176.                print(indent..tostring(t))
  177.            end
  178.        end
  179.    end
  180.    sub_print_r(t,"  ")
  181. end
  182. if usecolor and using_touchlua_app then
  183.    sys.setbgcolor(draw.black)
  184.    sys.setcolor(draw.red)
  185. end
  186. if usecolor and using_touchlua_app then
  187.    sys.setbgcolor(draw.black)
  188.    sys.setcolor(draw.green)
  189. end
  190. if docutscenes then
  191.    print("Booting") print("- - -")
  192.    sleep(cutsceneinterval)
  193.    os.execute("cls") clearlog()
  194.    print("Booting") print("| - -")
  195.    sleep(cutsceneinterval)
  196.    os.execute("cls") clearlog()
  197.    print("Booting") print("| | -")
  198.    sleep(cutsceneinterval)
  199.    os.execute("cls") clearlog()
  200.    print("Booting") print("| | |")
  201.    sleep(cutsceneinterval)
  202. end
  203. ::reclc::
  204. os.execute("cls")
  205. if not slowp then print("Enter an equation. * is multiply, / is divide, ^ followed by a number is an exponent. Type help to get advanced functions.") end
  206. if slowp==true then calcin=string.gsub(string.lower(calcin),"slowprint ","") local file=io.open("calculator logs.txt","r") log=file:read("*a") file:close() io.write("Enter an equation. * is multiply, / is divide, ^ followed by a number is an exponent. Type help to get advanced functions.") print(log) sleep(5000) slowprint(calcin,200) io.write("\n") slowp=false end
  207. clearlog()
  208. ::recalc::
  209. print("-------------")
  210. ::redocalc::
  211. calcin = io.read()
  212. if string.match(string.lower(calcin),"debug") then
  213.    ::drawdebug::
  214.    if usecolor and using_touchlua_app then
  215.        sys.setbgcolor(draw.black)
  216.        sys.setcolor(draw.red)
  217.    end
  218.    os.execute("cls")
  219.    for i=1,100 do
  220.        print("boot")
  221.        sleep(10)
  222.    end
  223.    os.execute("cls")
  224.    sleep(1000)
  225.    print("Debug mode enabled. Anti-crash safeguards disabled while in this mode. Debug commands enabled while in this mode. Scary red font enabled while in this mode. Type exit to leave.")
  226.    ::redebug::
  227.    print("=============")
  228.    io.write("debug> ")
  229.    local debugin=io.read()
  230.    debugin=string.lower(debugin)
  231.    if string.match(debugin,"panic") and createfiles==true then
  232.        file=io.open("calculator memory.txt","w")
  233.        file:write("-----------------\nCalculator Recall\n-----------------\n")
  234.        file:close()
  235.        clearlog()
  236.        goto drawdebug
  237.    end
  238.    if debugin=="exit" then
  239.        if usecolor and using_touchlua_app then
  240.            sys.setbgcolor(draw.black)
  241.            sys.setcolor(draw.green)
  242.        end
  243.        goto cls
  244.    end
  245.    if debugin=="cls" then goto drawdebug end
  246.    if debugin=="console" or debugin=="lua" then
  247.        if usecolor and using_touchlua_app then
  248.            sys.setcolor(draw.blue)
  249.            os.execute("cls")
  250.            while true do
  251.                io.write("Lua> ")
  252.                local luaIn=io.read()
  253.                if luaIn=="exit" then break end
  254.                load(luaIn)()
  255.            end
  256.            goto drawdebug
  257.        end
  258.    end
  259.    if string.match(debugin,"get") then
  260.        if string.match(debugin,"history") then
  261.            get("calculator memory.txt")
  262.            goto redebug
  263.        elseif string.match(debugin,"logs") then
  264.            get("calculator logs.txt")
  265.            goto redebug
  266.        end
  267.    end
  268.    if string.match(debugin,"sqrt") then
  269.        debugin=string.lower(debugin)
  270.        input=debugin
  271.        debugin = string.gsub(debugin,"sqrt","")
  272.        debugin=math.sqrt(debugin)
  273.        print("="..debugin)
  274.        glrb=debugin
  275.        debugin=input
  276.        goto redebug
  277.    elseif string.match(debugin,"factors") then
  278.        debugin=string.lower(debugin)
  279.        glrb=debugin
  280.        debugin = string.gsub(debugin,"factors","")
  281.        debugin=Factors(debugin)
  282.        print_r(debugin)
  283.        goto redebug
  284.    elseif string.match(debugin,"primefacs") then
  285.        debugin=string.lower(debugin)
  286.        glrb=debugin
  287.        debugin = string.gsub(debugin,"primefacs","")
  288.        debugin=tonumber(debugin)
  289.        debugin=PrimeDecomp(debugin)
  290.        print_r(debugin)
  291.        goto redebug
  292.    elseif string.match(debugin,"%%") then
  293.        input=debugin
  294.        tab=split(debugin)
  295.        perc=tab[1]
  296.        tot=tab[2]
  297.        glrb=percent(perc,tot)
  298.        print("="..glrb)
  299.        debugin=input
  300.        goto redebug
  301.    elseif string.match(debugin,"ee") then
  302.        input=debugin
  303.        tab=split(debugin,"ee")
  304.        zero=tab[1]
  305.        to=tab[2]
  306.        glrb=ee(zero,to)
  307.        print("="..glrb)
  308.        debugin=input
  309.        goto redebug
  310.    elseif string.match(debugin,"simplify") then
  311.        input=debugin
  312.        debugin=string.gsub(debugin,"simplify","")
  313.        glrb=simplify(debugin)
  314.        print("="..glrb)
  315.        debugin=input
  316.        goto redebug
  317.    elseif string.match(debugin,"factorial") then
  318.        input=debugin
  319.        debugin=string.gsub(debugin,"factorial","")
  320.        debugin=string.lower(debugin)
  321.        glrb=factorial(debugin)
  322.        print("="..glrb)
  323.        debugin=input
  324.        goto redebug
  325.    elseif string.match(debugin,"intocm") then
  326.        input=debugin
  327.        debugin=string.gsub(debugin,"intocm","")
  328.        glrb=debugin*2.54
  329.        print("="..glrb)
  330.        debugin=input
  331.        goto redebug
  332.    elseif string.match(debugin,"cm>in") then
  333.        input=debugin
  334.        debugin=string.gsub(debugin,"cm>in","")
  335.        glrb=debugin/2.54
  336.        print("="..glrb)
  337.        debugin=input
  338.        goto redebug
  339.    elseif string.match(debugin,"ft>m") then
  340.        input=debugin
  341.        debugin=string.gsub(debugin,"ft>m","")
  342.        glrb=debugin*3.28
  343.        print("="..glrb)
  344.        debugin=input
  345.        goto redebug
  346.    end
  347.    func = assert(load("return " .. debugin))
  348.    glrb = func()
  349.    if string.match(glrb,"-") then
  350.        print("=("..glrb..")")
  351.    else do
  352.            print("="..glrb)
  353.        end
  354.    end
  355.    goto redebug
  356. end
  357. if calcin=="an equation" then
  358.    os.execute("cls") clearlog()
  359.    slowprint("Good job.") sleep(3000) slowprint("\nYou win.") sleep(3000) slowprint("\nI'm out.") sleep(3000) slowprint("\nGG.") sleep(3000) os.exit()
  360. end
  361. if prevcalcin==calcin then crashcount=crashcount+1 end
  362. if prevcalcin~=calcin then crashcount=0 end
  363. if crashcount>=10 then error("keyspam detected.") end
  364. prevcalcin = calcin
  365. if string.match(string.lower(calcin),"slowprint ") then slowp=true goto reclc end
  366. local file=io.open("calculator logs.txt","a+")
  367. file:write("\n"..calcin)
  368. file:close()
  369. calcin=string.lower(calcin)
  370. if string.match(calcin,"panic") and createfiles==true then
  371.    file=io.open("calculator memory.txt","w")
  372.    file:write("-----------------\nCalculator Recall\n-----------------\n")
  373.     file:close()
  374.     clearlog()
  375.     goto cls
  376. elseif calcin=="cls" or calcin=="clear" then x=x+1 if x==20 and autoclear then os.execute("cls") clearlog()  goto recalc else end  goto cls
  377. elseif string.match(calcin,"#") and not prev then goto recalc
  378. elseif calcin=="clearmem" and createfiles==true then
  379.     os.execute("cls") clearlog()
  380.     print("Would you like to clear the calculator's memory file? \n(yes/no)")
  381.     if string.lower(io.read())~="yes" then goto reclc end
  382.     os.execute("cls") clearlog()
  383.     print("Are you absolutely sure that you want to clear the calculator's memory file? \n(yes/no)")
  384.     if string.lower(io.read())~="yes" then goto reclc end
  385.     os.execute("cls") clearlog()
  386.     print("Last chance to stop. Are you sure that you would like to clear the calculator's memory file? \n(yes/no)")
  387.     if string.lower(io.read())~="yes" then goto reclc end
  388.     os.execute("cls") clearlog()
  389.     print("Alright. Clearing calculator's memory file...") print("- - -") sleep(cutsceneinterval) os.execute("cls") clearlog()
  390.     print("Alright. Clearing calculator's memory file...") print("| - -") sleep(cutsceneinterval) os.execute("cls") clearlog()
  391.     print("Alright. Clearing calculator's memory file...") print("| | -") sleep(cutsceneinterval) os.execute("cls") clearlog()
  392.     print("Alright. Clearing calculator's memory file...") print("| | |") sleep(cutsceneinterval) os.execute("cls") clearlog()
  393.     file=io.open("calculator memory.txt","w")
  394.     file:write("-----------------\nCalculator Recall\n-----------------\n")
  395.     file:close()
  396.     print([=[Calculator's memory file "calculator memory.txt" has been cleared.]=])
  397.    print("Press any button to continue.")
  398.    io.read()
  399.    goto cls
  400. elseif calcin=="" or calcin==" " then x=x+1 if x==20 and autoclear then os.execute("cls") clearlog()  goto recalc else end  goto recalc
  401. elseif string.match(calcin,",") then
  402.    calcin=string.gsub(calcin,",","")
  403. elseif string.match(calcin,"=") then
  404.    calcin=string.gsub(calcin,"=","")
  405. elseif calcin=="time" then
  406.    os.execute("cls")
  407.    local file=io.open("calculator logs.txt","r")
  408.    log=file:read("*a")
  409.    file:close()
  410.    io.write("Enter an equation. * is multiply, / is divide, ^ followed by a number is an exponent. Type help to get advanced functions.")
  411.    local log=string.gsub(log,"\ntime","")
  412.    print(log)
  413.    time=os.date("%I:%M:%S %p on %A, %B %d, %Y")
  414.    print(time)
  415.    goto recalc
  416. elseif calcin=="help" then print("-------------")print([=[time = get the date and time
  417. sqrt = type this, followed by a number, to get that
  418.       number's square root (i.e. sqrt10)
  419. factors = type this, followed by a number, to get that
  420.           number's factors (i.e. factors10)
  421. simplify = type this, followed by a fraction, to get the
  422.           simplified version of that fraction (i.e.  
  423.           simplify2/4)
  424. factorial = type this, followed by a number, to get the
  425.            result of multiplying a series of descending
  426.            numbers, starting with the given number (i.e.
  427.            factorial5)
  428. cmtoin = type this, followed by a number in centimeters,
  429.         to convert that number to inches (i.e. cmtoin42)
  430. intocm = type this, followed by a number in inches, to
  431.         convert that number to centimeters (i.e. intocm8)
  432. mtoft = type this, followed by a number in meters, to
  433.        convert that number to feet (i.e. mtoft5)
  434. fttom = type this, followed by a number in feet, to
  435.        convert that number to meters (i.e. fttom16)
  436. # = substitute for the previous result
  437. slowprint = type this, followed by a space and some
  438.            text, to print out that text after 5 seconds
  439.            (i.e. slowprint hello)
  440. % = type a number, followed by %, followed by another
  441.    number, to get the number that is the first number's
  442.     percentage of the second number (i.e. 10%20)
  443. pi = substitute for the first 14 digits of pi (i.e. pi*pi)
  444. ee = substitute for [first number]*10^[second number]
  445.      (i.e. 2ee4)
  446. sq = substitute for ^2 (i.e. 2sq)
  447. cu = substitute for ^3 (i.e. 3cu)
  448. clear = type this to clear the screen
  449. cls = alias for clear
  450. primefacs = type this, followed by a number, to get the
  451.             prime factors of that number (i.e. primefacs10)
  452. clearmem = clear the "calculator memory.txt" file]=])
  453. end
  454. if not string.match(calcin,match) or string.match(calcin,"=") then goto recalc
  455. elseif string.match(calcin,match) then
  456.     if not string.match(calcin,"sqrt") then
  457.         calcin=string.gsub(calcin,"sq","^2")
  458.     end
  459.     calcin=string.gsub(calcin,"pi",math.pi)
  460.     if prev then
  461.         calcin = string.gsub(calcin,"#",prev)
  462.     end
  463.     --start
  464.     if string.match(calcin,"sqrt") and string.match(calcin,"[0123456789]") and not string.match(calcin," ") then
  465.         calcin=string.lower(calcin)
  466.         input=calcin
  467.         calcin = string.gsub(calcin,"sqrt","")
  468.         if string.match(calcin,notmatch) or string.match(calcin,"[/-*^+()#]") then goto recalc end
  469.         pc,calcin=pcall(math.sqrt,calcin)
  470.         if not pc then goto recalc end
  471.         print("="..calcin)
  472.         glrb=calcin
  473.         calcin=input
  474.         goto skipcalcu
  475.     elseif string.match(calcin,"factors") and string.match(calcin,"[0123456789]") and not string.match(calcin," ") then
  476.         calcin=string.lower(calcin)
  477.         glrb=calcin
  478.         calcin = string.gsub(calcin,"factors","")
  479.         if string.match(calcin,notmatch) or string.match(calcin,"[/-*^+()#]") then goto recalc end
  480.         pc,calcin=pcall(Factors,calcin)
  481.         if not pc then goto recalc end
  482.         print_r(calcin)
  483.         goto noprev
  484.     elseif string.match(calcin,"primefacs") and string.match(calcin,"[0123456789]") and not string.match(calcin," ") then
  485.         calcin=string.lower(calcin)
  486.         glrb=calcin
  487.         calcin = string.gsub(calcin,"primefacs","")
  488.         if string.match(calcin,notmatch) or string.match(calcin,"[/-*^+()#]") then goto recalc end
  489.         calcin=tonumber(calcin)
  490.         pc,calcin=pcall(PrimeDecomp,calcin)
  491.         if not pc then goto recalc end
  492.         print_r(calcin)
  493.         goto noprev
  494.     elseif string.match(calcin,"%%") and string.match(calcin,match) and not string.match(calcin," ") then
  495.         input=calcin
  496.         tab=split(calcin)
  497.         if string.match(tab[1],notmatch) or string.match(tab[1],"[/-*^+()#]") then goto recalc end
  498.         if string.match(tab[2],notmatch) or string.match(tab[2],"[/-*^+()#]") then goto recalc end
  499.         perc=tab[1]
  500.         tot=tab[2]
  501.         pc,glrb=pcall(percent,perc,tot)
  502.         if not pc then goto recalc end
  503.         print("="..glrb)
  504.         calcin=input
  505.         goto skipcalcu
  506.     elseif string.match(calcin,"ee") and string.match(calcin,match) and not string.match(calcin," ") then
  507.         input=calcin
  508.         tab=split(calcin,"ee")
  509.         if string.match(tab[1],notmatch) or string.match(tab[1],"[/-*^+()#]") then goto recalc end
  510.         if string.match(tab[2],notmatch) or string.match(tab[2],"[/-*^+()#]") then goto recalc end
  511.         zero=tab[1]
  512.         to=tab[2]
  513.         pc,glrb=pcall(ee,zero,to)
  514.         if not pc then goto recalc end
  515.         print("="..glrb)
  516.         calcin=input
  517.         goto skipcalcu
  518.     elseif string.match(calcin,"simplify") and string.match(calcin,match) and string.match(calcin,"/") and not string.match(calcin," ") then
  519.         input=calcin
  520.         calcin=string.gsub(calcin,"simplify","")
  521.         if string.match(calcin,notmatch) or string.match(calcin,"[-*^+()#]") then goto recalc end
  522.         pc,glrb=pcall(simplify,calcin)
  523.         if not pc then goto recalc end
  524.         print("="..glrb)
  525.         calcin=input
  526.         goto skipcalcu
  527.     elseif string.match(calcin,"factorial") and string.match(calcin,match) and not string.match(calcin," ") then
  528.         input=calcin
  529.         calcin=string.gsub(calcin,"factorial","")
  530.         calcin=string.lower(calcin)
  531.         if string.match(calcin,notmatch) or string.match(calcin,"[-*^+()#]") then goto recalc end
  532.         pc,glrb=pcall(factorial,calcin)
  533.         if not pc then goto recalc end
  534.         print("="..glrb)
  535.         calcin=input
  536.         goto skipcalcu
  537.     elseif string.match(calcin,"intocm") and string.match(calcin,match) and not string.match(calcin," ") then
  538.         input=calcin
  539.         calcin=string.gsub(calcin,"intocm","")
  540.         if string.match(calcin,notmatch) or string.match(calcin,"[-*^+()#]") then goto recalc end
  541.         glrb=calcin*2.54
  542.         print("="..glrb)
  543.         calcin=input
  544.         goto skipcalcu
  545.     elseif string.match(calcin,"cm>in") and string.match(calcin,match) and not string.match(calcin," ") then
  546.         input=calcin
  547.         calcin=string.gsub(calcin,"cm>in","")
  548.         if string.match(calcin,notmatch) or string.match(calcin,"[-*^+()#]") then goto recalc end
  549.         glrb=calcin/2.54
  550.         print("="..glrb)
  551.         calcin=input
  552.         goto skipcalcu
  553.     elseif string.match(calcin,"ft>m") and string.match(calcin,match) and not string.match(calcin," ") then
  554.         input=calcin
  555.         calcin=string.gsub(calcin,"ft>m","")
  556.         if string.match(calcin,notmatch) or string.match(calcin,"[-*^+()#]") then goto recalc end
  557.         glrb=calcin*3.28
  558.         print("="..glrb)
  559.         calcin=input
  560.         goto skipcalcu
  561.         --end
  562.     elseif string.match(calcin,"sq") and string.match(calcin,match) then calcin=string.gsub(calcin,"sq","^2")
  563.     elseif string.match(calcin,"cu") and string.match(calcin,match) then calcin=string.gsub(calcin,"cu","^3")
  564.     elseif string.match(calcin,"pi") and string.match(calcin,match) then calcin=string.gsub(calcin,"pi",math.pi)
  565.     elseif string.match(calcin,"/0") then goto recalc
  566.     elseif string.match(calcin,"#") and string.match(calcin,match) and prev~=nil then
  567.         calcin = string.gsub(calcin,"#",prev)
  568.     end
  569. end
  570. if string.match(calcin,notmatch) or string.match(calcin,"]") then goto recalc end
  571. if unexpected_condition then goto recalc end
  572. pc,func = pcall(assert,load("return " .. calcin))
  573. if not pc then goto recalc end
  574. glrb = func()
  575. if glrb==9001 then print("=OVER 9000 (real answer: 9001)") goto skipcalcu end
  576. if tostring(glrb)==tostring(calcin) then goto recalc end
  577. if string.match(glrb,"-") then
  578.     print("=("..glrb..")")
  579. else do
  580.         print("="..glrb)
  581.     end
  582. end
  583. ::skipcalcu::
  584. prev=glrb
  585. calcin=tostring(calcin)
  586. date=os.date()
  587. if createfiles then
  588.     file=io.open("calculator memory.txt","a+")
  589.     if string.match(glrb,"-") then
  590.         file:write("\n"..date.."\n"..calcin.." = ("..glrb..")\n")
  591.     else do
  592.             file:write("\n"..date.."\n"..calcin.." = "..glrb.."\n")
  593.         end
  594.     end
  595.     file:close()
  596. end
  597. ::noprev::
  598. x=x+1 if x==20 and autoclear then os.execute("cls") clearlog()  goto recalc else end
  599. goto recalc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement