Advertisement
Guest User

mlua

a guest
Jan 30th, 2018
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 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.  
  37. local tEnv = {
  38.     ["exit"] = function()
  39. bRunning = false
  40. end,
  41.  ["_echo"] = function( ... )
  42.  return ...
  43.  end,
  44.    
  45. }
  46. setmetatable( tEnv, { __index = _ENV } )
  47. fg=term.setTextColor
  48. bg=term.setBackgroundColor
  49. cp=term.setCursorPos
  50. c=colors
  51.  
  52. if term.isColor() then
  53.     term.setTextColor( colors.yellow )
  54. end
  55. fg(c.green)
  56. print( "Interactive Lua prompt." )
  57. print( "Call exit() to exit OR just type 'exit'." )
  58. print( " " )
  59. fg( colors.lime )
  60. print( "Modified Version by Gabriel Sharp (C)2017-18" )
  61. fg( c.magenta )
  62. print( "osirisgothra@hotmail.com" )
  63. print( " " )
  64. bg( c.blue )
  65. fg( c.cyan )
  66. print ( "// 1.7 completion edition! //" )
  67. bg (c.black)
  68. print(" ")
  69. fg( c.white )
  70.  
  71.  
  72. while bRunning do
  73.     --if term.isColour() then
  74.     --  term.setTextColour( colours.yellow )
  75.     --end
  76.  if term.isColor() then
  77.    term.setTextColor( colors.lime )
  78.    write( shell.dir() )
  79.    write( "mlua" )
  80.    term.setTextColor( colors.gray )
  81.    write( "> " )
  82.    term.setTextColor( colors.white )
  83.  else
  84.    write("mlua: ")
  85.  end
  86.     --write( "lua> " )
  87.     --term.setTextColour( colours.white )
  88.    
  89.     local s = read( nil, tCommandHistory, function( sLine )
  90.  -- if true then
  91.  -- settings.get( "lua.autocomplete" ) then
  92.    local nStartPos = string.find( sLine, "[A-Za-z0-9_%.]+" )
  93.    if nStartPos then
  94.      sLine = string.sub( sLine, nStartPos )
  95.    end
  96.    if #sLine > 0 then
  97.      return textutils.complete( sLine, tEnv )  
  98.    end
  99.  -- end
  100.  return nil
  101.  end )
  102.  
  103.  if s == "exit" then
  104.    print("automatically interpreted command exit as exit()")
  105.    s = "exit()"
  106.  elseif string.sub(s,1,1) == "!" then
  107.    s = "shell.run('"..string.sub(s,2) .. "')"
  108.  end
  109.  
  110.  -- print(s)
  111.  
  112.     table.insert( tCommandHistory, s )
  113.  --print(s)
  114.  
  115.     local nForcePrint = 0
  116.  
  117.     local func, e = load( s, "lua", "t", tEnv )
  118.     local func2, e2 = load( "return _echo("..s..");", "lua", "t", tEnv )
  119.     if not func then
  120.         if func2 then
  121.             func = func2
  122.             e = nil
  123.             nForcePrint = 1
  124.         end
  125.     else
  126.         if func2 then
  127.             func = func2
  128.         end
  129.     end
  130.    
  131.     if func then
  132. --- was removed for 7.1 final (set/getfenv inferior, using _ENV instead!)
  133. --- updated from 7.1's beta compatability versions
  134. ---        setfenv( func, tEnv )
  135.         local tResults = { pcall ( func ) }
  136.         if tResults[1] then
  137.             local n = 1
  138.             while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
  139.             if type(tResults[n+1]) == "nil" then
  140.                print("nil (empty value)")
  141.             elseif type(tResults[n+1]) == "table" then
  142.               local i=0
  143.               local _,max = term.getSize()
  144.               for dim,val in pairs(tResults[n+1]) do
  145.                term.setTextColor(colors.gray)
  146.                write(dim)
  147.                write("  ")
  148.                term.setTextColor(colors.green)
  149.                print(val)
  150.                term.setTextColor(colors.white)
  151.                i=i+1
  152.                if i > (max-3) then
  153.                  term.setTextColor(colors.cyan)
  154.                  term.write("[")
  155.                  term.setTextColor(colors.blue)
  156.                  term.write("Press Any Key")
  157.                  term.setTextColor(colors.cyan)
  158.                  term.write("]")
  159.                  term.setTextColor(colors.white)
  160.                  while not os.pullEvent() == "key" do
  161.                   sleep(0.25)
  162.                  end
  163.                  
  164.                  term.clearLine()
  165.                  i=0
  166.                end
  167.               end
  168.             else
  169.                print( tostring( tResults[n+1] ) )
  170.             end
  171.             term.setTextColor(colors.blue)
  172.             print("type ",type(tResults[n+1]))
  173.             term.setTextColor(colors.white)            
  174.                 n = n + 1        
  175.             end
  176.         else
  177.             printError( tResults[2] )
  178.         end
  179.     else
  180.         printError( e )
  181.     end    
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement