Guest User

lua

a guest
Jan 29th, 2018
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. -- ANVI.COREPROG-MLUA
  2. -- mlua rev 1.3 (C)2017 osirisgothra@hotmail.com
  3. -- written by Gabriel T. Sharp, no distribution without written concent
  4. --
  5.  
  6. local tArgs = { ... }
  7. if #tArgs > 0 then
  8.  print( "Modified Version of LUA Interpreter")
  9.  print( "(C)2017 by Gabriel Sharp")
  10.  print( "osirisgothra@hotmail.com")
  11.     print( "This is an interactive Lua prompt." )
  12.     print( "To run a lua program, just type its name." )
  13.     return
  14. end
  15. function nocolor()
  16.   if false then
  17.     print('never happens')
  18.   end
  19. end
  20.  
  21. if term.isColor() then
  22. --  old_setColor = term.setTextColor
  23. --  old_setColorB = term.setBackgroundColor
  24.    nocolor = nil
  25. else
  26. --  old_setColor = nocolor
  27. --  old_setColorB = nocolor
  28.    term.setTextColor = nocolor
  29.    term.setBackgroundColor = nocolor
  30. end
  31.  
  32.  
  33.  
  34. local bRunning = true
  35. local tCommandHistory = {}
  36. local tEnv = {
  37.     ["exit"] = function()
  38.         bRunning = false
  39.     end,
  40. }
  41. setmetatable( tEnv, { __index = getfenv() } )
  42.  
  43. if term.isColor() then
  44.     term.setTextColor( colors.yellow )
  45. end
  46. print( "Interactive Lua prompt." )
  47. print( "Call exit() to exit OR just type 'exit'." )
  48. print( " " )
  49. term.setTextColor( colors.green )
  50. print( "Modified Version by Gabriel Sharp (C)2017" )
  51. print( "osirisgothra@hotmail.com" )
  52. print( " " )
  53. term.setTextColour( colours.white )
  54.  
  55. while bRunning do
  56.     --if term.isColour() then
  57.     --  term.setTextColour( colours.yellow )
  58.     --end
  59.  if term.isColor() then
  60.    term.setTextColor( colors.lime )
  61.    write( "mlua" )
  62.    term.setTextColor( colors.gray )
  63.    write( "> " )
  64.    term.setTextColor( colors.white )
  65.  else
  66.    write("mlua: ")
  67.  end
  68.     --write( "lua> " )
  69.     --term.setTextColour( colours.white )
  70.    
  71.     local s = read( nil, tCommandHistory )
  72.  if s == "exit" then
  73.    print("automatically interpreted command exit as exit()")
  74.    s = "exit()"
  75.  elseif string.sub(s,1,1) == "!" then
  76.    s = "shell.run('"..string.sub(s,2) .. "')"
  77.  end
  78.  print(s)
  79.  
  80.     table.insert( tCommandHistory, s )
  81.  --print(s)
  82.  
  83.     local nForcePrint = 0
  84.     local func, e = loadstring( s, "lua" )
  85.     local func2, e2 = loadstring( "return "..s, "lua" )
  86.     if not func then
  87.         if func2 then
  88.             func = func2
  89.             e = nil
  90.             nForcePrint = 1
  91.         end
  92.     else
  93.         if func2 then
  94.             func = func2
  95.         end
  96.     end
  97.    
  98.     if func then
  99.         setfenv( func, tEnv )
  100.         local tResults = { pcall( function() return func() end ) }
  101.         if tResults[1] then
  102.             local n = 1
  103.             while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
  104.             if type(tResults[n+1]) == "nil" then
  105.                print("nil (empty value)")
  106.             elseif type(tResults[n+1]) == "table" then
  107.               local i=0
  108.               local _,max = term.getSize()
  109.               for dim,val in pairs(tResults[n+1]) do
  110.                term.setTextColor(colors.gray)
  111.                write(dim)
  112.                write("  ")
  113.                term.setTextColor(colors.green)
  114.                print(val)
  115.                term.setTextColor(colors.white)
  116.                i=i+1
  117.                if i > (max-3) then
  118.                  term.setTextColor(colors.cyan)
  119.                  term.write("[")
  120.                  term.setTextColor(colors.blue)
  121.                  term.write("Press Any Key")
  122.                  term.setTextColor(colors.cyan)
  123.                  term.write("]")
  124.                  term.setTextColor(colors.white)
  125.                  while not os.pullEvent() == "key" do
  126.                   sleep(0.25)
  127.                  end
  128.                  
  129.                  term.clearLine()
  130.                  i=0
  131.                end
  132.               end
  133.             else
  134.                print( tostring( tResults[n+1] ) )
  135.             end
  136.             term.setTextColor(colors.blue)
  137.             print("type ",type(tResults[n+1]))
  138.             term.setTextColor(colors.white)            
  139.                 n = n + 1        
  140.             end
  141.         else
  142.             printError( tResults[2] )
  143.         end
  144.     else
  145.         printError( e )
  146.     end    
  147. end
Add Comment
Please, Sign In to add comment