jesusthekiller

LuaOS Cheaty

Jun 21st, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.84 KB | None | 0 0
  1. --[[
  2.     Project info:
  3.    
  4.     Name: LuaOS
  5.     Creator: Jesusthekiller
  6.     Language: Lua (CC)
  7.     Website: None
  8.     License: GNU GPL
  9.         License file can be fount at www.jesusthekiller.com/license-gpl.html
  10.  
  11.     Version: 1.1
  12. ]]--
  13.  
  14. --[[
  15.     Changelog:
  16.       1.0:
  17.         Initial Release
  18.       1.1:
  19.         Cheaty LuaOS release
  20. ]]--
  21.  
  22. --[[
  23.     LICENSE:
  24.    
  25.     LuaOS
  26.     Copyright (c) 2013 Jesusthekiller
  27.  
  28.     This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  29.  
  30.     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  31.  
  32.     See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  33. ]]--
  34.  
  35. term.setBackgroundColor(colors.black)
  36. term.setTextColor(colors.white)
  37. term.clear()
  38. term.setCursorPos(1, 1)
  39.  
  40. -- COPIED (edited a bit) FROM CRAFTOS SHELL:
  41. local bExit = false
  42. local sDir = ""
  43. local sPath = ".:/rom/programs"
  44. local tAliases = {}
  45. local tProgramStack = {}
  46.  
  47. local shell = {}
  48. local tEnv = {
  49.     ["shell"] = shell,
  50. }
  51.  
  52. local function run( _sCommand, ... )
  53.     local sPath = shell.resolveProgram( _sCommand )
  54.     if sPath ~= nil then
  55.         tProgramStack[#tProgramStack + 1] = sPath
  56.         local result = os.run( tEnv, sPath, ... )
  57.         tProgramStack[#tProgramStack] = nil
  58.         return result
  59.     else
  60.         printError( "No such program" )
  61.         return false
  62.     end
  63. end
  64.  
  65. local function runLine( _sLine )
  66.     local tWords = {}
  67.     for match in string.gmatch( _sLine, "[^ \t]+" ) do
  68.         table.insert( tWords, match )
  69.     end
  70.  
  71.     local sCommand = tWords[1]
  72.     if sCommand then
  73.         return run( sCommand, unpack( tWords, 2 ) )
  74.     end
  75.     return false
  76. end
  77.  
  78. function shell.run( ... )
  79.     return runLine( table.concat( { ... }, " " ) )
  80. end
  81.  
  82. function shell.exit()
  83.     os.shutdown()
  84. end
  85.  
  86. function shell.dir()
  87.     return sDir
  88. end
  89.  
  90. function shell.setDir( _sDir )
  91.     sDir = _sDir
  92. end
  93.  
  94. function shell.path()
  95.     return sPath
  96. end
  97.  
  98. function shell.setPath( _sPath )
  99.     sPath = _sPath
  100. end
  101.  
  102. function shell.resolve( _sPath )
  103.     local sStartChar = string.sub( _sPath, 1, 1 )
  104.     if sStartChar == "/" or sStartChar == "\\" then
  105.         return fs.combine( "", _sPath )
  106.     else
  107.         return fs.combine( sDir, _sPath )
  108.     end
  109. end
  110.  
  111. function shell.resolveProgram( _sCommand )
  112.     -- Substitute aliases firsts
  113.     if tAliases[ _sCommand ] ~= nil then
  114.         _sCommand = tAliases[ _sCommand ]
  115.     end
  116.  
  117.     -- If the path is a global path, use it directly
  118.     local sStartChar = string.sub( _sCommand, 1, 1 )
  119.     if sStartChar == "/" or sStartChar == "\\" then
  120.         local sPath = fs.combine( "", _sCommand )
  121.         if fs.exists( sPath ) and not fs.isDir( sPath ) then
  122.             return sPath
  123.         end
  124.         return nil
  125.     end
  126.    
  127.     -- Otherwise, look on the path variable
  128.     for sPath in string.gmatch(sPath, "[^:]+") do
  129.         sPath = fs.combine( shell.resolve( sPath ), _sCommand )
  130.         if fs.exists( sPath ) and not fs.isDir( sPath ) then
  131.             return sPath
  132.         end
  133.     end
  134.    
  135.     -- Not found
  136.     return nil
  137. end
  138.  
  139. function shell.programs( _bIncludeHidden )
  140.     local tItems = {}
  141.    
  142.     -- Add programs from the path
  143.     for sPath in string.gmatch(sPath, "[^:]+") do
  144.         sPath = shell.resolve( sPath )
  145.         if fs.isDir( sPath ) then
  146.             local tList = fs.list( sPath )
  147.             for n,sFile in pairs( tList ) do
  148.                 if not fs.isDir( fs.combine( sPath, sFile ) ) and
  149.                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
  150.                     tItems[ sFile ] = true
  151.                 end
  152.             end
  153.         end
  154.     end
  155.  
  156.     -- Sort and return
  157.     local tItemList = {}
  158.     for sItem, b in pairs( tItems ) do
  159.         table.insert( tItemList, sItem )
  160.     end
  161.     table.sort( tItemList )
  162.     return tItemList
  163. end
  164.  
  165. function shell.getRunningProgram()
  166.     if #tProgramStack > 0 then
  167.         return tProgramStack[#tProgramStack]
  168.     end
  169.     return nil
  170. end
  171.  
  172. function shell.setAlias( _sCommand, _sProgram )
  173.     tAliases[ _sCommand ] = _sProgram
  174. end
  175.  
  176. function shell.clearAlias( _sCommand )
  177.     tAliases[ _sCommand ] = nil
  178. end
  179.  
  180. function shell.aliases()
  181.     -- Add aliases
  182.     local tCopy = {}
  183.     for sAlias, sCommand in pairs( tAliases ) do
  184.         tCopy[sAlias] = sCommand
  185.     end
  186.     return tCopy
  187. end
  188. -- END OF COPY
  189.  
  190. -- ######################################################################################################
  191.  
  192. print("LuaOS Successfully booted!")
  193. print("Lua 5.2\n")
  194.  
  195. shell.run("rom/startup")
  196.  
  197. if fs.exists("_startup") then
  198.     shell.run("_startup")
  199. end
  200.  
  201. local tCmds = {}
  202.  
  203. while true do
  204.     write("> ")
  205.     local cmd = read(nil, tCmds)
  206.    
  207.     table.insert(tCmds, cmd)
  208.    
  209.     cmd = (cmd == "help") and ".help" or cmd
  210.    
  211.     if cmd:sub(1,1) == "." then
  212.         if cmd:lower() == ".reboot" then
  213.             os.reboot()
  214.         elseif cmd:lower() == ".shutdown" then
  215.             os.shutdown()
  216.         elseif cmd:lower():sub(1,5) == ".help" then
  217.             print("To execute files (as in CraftOS): .<cmd> <args>")
  218.             print("Everything else is run as Lua code")
  219.         else
  220.             shell.run(cmd:sub(2))
  221.         end
  222.     else
  223.         local s = cmd
  224.         -- COPIED FROM "LUA"
  225.         local nForcePrint = 0
  226.         local func, e = loadstring( s, "lua" )
  227.         local func2, e2 = loadstring( "return "..s, "lua" )
  228.         if not func then
  229.             if func2 then
  230.                 func = func2
  231.                 e = nil
  232.                 nForcePrint = 1
  233.             end
  234.         else
  235.             if func2 then
  236.                 func = func2
  237.             end
  238.         end
  239.        
  240.         if func then
  241.             -- setfenv( func, tEnv )
  242.             local tResults = { pcall( function() return func() end ) }
  243.             if tResults[1] then
  244.                 local n = 1
  245.                 while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
  246.                     print( tostring( tResults[n + 1] ) )
  247.                     n = n + 1
  248.                 end
  249.             else
  250.                 printError( tResults[2] )
  251.             end
  252.         else
  253.             printError( e )
  254.         end
  255.         -- END OF COPY
  256.     end
  257. end
  258.  
  259. shell.exit()
Advertisement
Add Comment
Please, Sign In to add comment