Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ANVI.COREPROG-MLUA
- -- mlua rev 1.3 (C)2017 osirisgothra@hotmail.com
- -- written by Gabriel T. Sharp, no distribution without written concent
- --
- local tArgs = { ... }
- if #tArgs > 0 then
- print( "Modified Version of LUA Interpreter")
- print( "(C)2017 by Gabriel Sharp")
- print( "osirisgothra@hotmail.com")
- print( "This is an interactive Lua prompt." )
- print( "To run a lua program, just type its name." )
- return
- end
- function nocolor()
- if false then
- print('never happens')
- end
- end
- if term.isColor() then
- -- old_setColor = term.setTextColor
- -- old_setColorB = term.setBackgroundColor
- nocolor = nil
- else
- -- old_setColor = nocolor
- -- old_setColorB = nocolor
- term.setTextColor = nocolor
- term.setBackgroundColor = nocolor
- end
- local bRunning = true
- local tCommandHistory = {}
- local tEnv = {
- ["exit"] = function()
- bRunning = false
- end,
- }
- setmetatable( tEnv, { __index = getfenv() } )
- if term.isColor() then
- term.setTextColor( colors.yellow )
- end
- print( "Interactive Lua prompt." )
- print( "Call exit() to exit OR just type 'exit'." )
- print( " " )
- term.setTextColor( colors.green )
- print( "Modified Version by Gabriel Sharp (C)2017" )
- print( "osirisgothra@hotmail.com" )
- print( " " )
- term.setTextColour( colours.white )
- while bRunning do
- --if term.isColour() then
- -- term.setTextColour( colours.yellow )
- --end
- if term.isColor() then
- term.setTextColor( colors.lime )
- write( "mlua" )
- term.setTextColor( colors.gray )
- write( "> " )
- term.setTextColor( colors.white )
- else
- write("mlua: ")
- end
- --write( "lua> " )
- --term.setTextColour( colours.white )
- local s = read( nil, tCommandHistory )
- if s == "exit" then
- print("automatically interpreted command exit as exit()")
- s = "exit()"
- elseif string.sub(s,1,1) == "!" then
- s = "shell.run('"..string.sub(s,2) .. "')"
- end
- print(s)
- table.insert( tCommandHistory, s )
- --print(s)
- local nForcePrint = 0
- local func, e = loadstring( s, "lua" )
- local func2, e2 = loadstring( "return "..s, "lua" )
- if not func then
- if func2 then
- func = func2
- e = nil
- nForcePrint = 1
- end
- else
- if func2 then
- func = func2
- end
- end
- if func then
- setfenv( func, tEnv )
- local tResults = { pcall( function() return func() end ) }
- if tResults[1] then
- local n = 1
- while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
- if type(tResults[n+1]) == "nil" then
- print("nil (empty value)")
- elseif type(tResults[n+1]) == "table" then
- local i=0
- local _,max = term.getSize()
- for dim,val in pairs(tResults[n+1]) do
- term.setTextColor(colors.gray)
- write(dim)
- write(" ")
- term.setTextColor(colors.green)
- print(val)
- term.setTextColor(colors.white)
- i=i+1
- if i > (max-3) then
- term.setTextColor(colors.cyan)
- term.write("[")
- term.setTextColor(colors.blue)
- term.write("Press Any Key")
- term.setTextColor(colors.cyan)
- term.write("]")
- term.setTextColor(colors.white)
- while not os.pullEvent() == "key" do
- sleep(0.25)
- end
- term.clearLine()
- i=0
- end
- end
- else
- print( tostring( tResults[n+1] ) )
- end
- term.setTextColor(colors.blue)
- print("type ",type(tResults[n+1]))
- term.setTextColor(colors.white)
- n = n + 1
- end
- else
- printError( tResults[2] )
- end
- else
- printError( e )
- end
- end
Add Comment
Please, Sign In to add comment