wow0

Untitled

Nov 4th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.03 KB | None | 0 0
  1.  
  2. local nativegetfenv = getfenv
  3. if _VERSION == "Lua 5.1" then
  4. -- If we're on Lua 5.1, install parts of the Lua 5.2/5.3 API so that programs can be written against it
  5. local nativeload = load
  6. local nativeloadstring = loadstring
  7. local nativesetfenv = setfenv
  8. function load( x, name, mode, env )
  9. if mode ~= nil and mode ~= "t" then
  10. error( "Binary chunk loading prohibited", 2 )
  11. end
  12. local ok, p1, p2 = pcall( function()
  13. if type(x) == "string" then
  14. local result, err = nativeloadstring( x, name )
  15. if result then
  16. if env then
  17. env._ENV = env
  18. nativesetfenv( result, env )
  19. end
  20. return result
  21. else
  22. return nil, err
  23. end
  24. else
  25. local result, err = nativeload( x, name )
  26. if result then
  27. if env then
  28. env._ENV = env
  29. nativesetfenv( result, env )
  30. end
  31. return result
  32. else
  33. return nil, err
  34. end
  35. end
  36. end )
  37. if ok then
  38. return p1, p2
  39. else
  40. error( p1, 2 )
  41. end
  42. end
  43. table.unpack = unpack
  44. table.pack = function( ... ) return { n = select( "#", ... ), ... } end
  45.  
  46. -- Install the bit32 api
  47. local nativebit = bit
  48. bit32 = {}
  49. bit32.arshift = nativebit.brshift
  50. bit32.band = nativebit.band
  51. bit32.bnot = nativebit.bnot
  52. bit32.bor = nativebit.bor
  53. bit32.btest = function( a, b ) return nativebit.band(a,b) ~= 0 end
  54. bit32.bxor = nativebit.bxor
  55. bit32.lshift = nativebit.blshift
  56. bit32.rshift = nativebit.blogic_rshift
  57.  
  58. if _CC_DISABLE_LUA51_FEATURES then
  59. -- Remove the Lua 5.1 features that will be removed when we update to Lua 5.2, for compatibility testing.
  60. -- See "disable_lua51_functions" in ComputerCraft.cfg
  61. setfenv = nil
  62. getfenv = nil
  63. loadstring = nil
  64. unpack = nil
  65. math.log10 = nil
  66. table.maxn = nil
  67. bit = nil
  68. end
  69. end
  70.  
  71. if _VERSION == "Lua 5.3" then
  72. -- If we're on Lua 5.3, install the bit32 api from Lua 5.2
  73. -- (Loaded from a string so this file will still parse on <5.3 lua)
  74. load( [[
  75. bit32 = {}
  76.  
  77. function bit32.arshift( n, bits )
  78. if type(n) ~= "number" or type(bits) ~= "number" then
  79. error( "Expected number, number", 2 )
  80. end
  81. return n >> bits
  82. end
  83.  
  84. function bit32.band( m, n )
  85. if type(m) ~= "number" or type(n) ~= "number" then
  86. error( "Expected number, number", 2 )
  87. end
  88. return m & n
  89. end
  90.  
  91. function bit32.bnot( n )
  92. if type(n) ~= "number" then
  93. error( "Expected number", 2 )
  94. end
  95. return ~n
  96. end
  97.  
  98. function bit32.bor( m, n )
  99. if type(m) ~= "number" or type(n) ~= "number" then
  100. error( "Expected number, number", 2 )
  101. end
  102. return m | n
  103. end
  104.  
  105. function bit32.btest( m, n )
  106. if type(m) ~= "number" or type(n) ~= "number" then
  107. error( "Expected number, number", 2 )
  108. end
  109. return (m & n) ~= 0
  110. end
  111.  
  112. function bit32.bxor( m, n )
  113. if type(m) ~= "number" or type(n) ~= "number" then
  114. error( "Expected number, number", 2 )
  115. end
  116. return m ~ n
  117. end
  118.  
  119. function bit32.lshift( n, bits )
  120. if type(n) ~= "number" or type(bits) ~= "number" then
  121. error( "Expected number, number", 2 )
  122. end
  123. return n << bits
  124. end
  125.  
  126. function bit32.rshift( n, bits )
  127. if type(n) ~= "number" or type(bits) ~= "number" then
  128. error( "Expected number, number", 2 )
  129. end
  130. return n >> bits
  131. end
  132. ]] )()
  133. end
  134.  
  135. if string.find( _HOST, "ComputerCraft" ) == 1 then
  136. -- Prevent access to metatables or environments of strings, as these are global between all computers
  137. local nativegetmetatable = getmetatable
  138. local nativeerror = error
  139. local nativetype = type
  140. local string_metatable = nativegetmetatable("")
  141. function getmetatable( t )
  142. local mt = nativegetmetatable( t )
  143. if mt == string_metatable then
  144. nativeerror( "Attempt to access string metatable", 2 )
  145. else
  146. return mt
  147. end
  148. end
  149. if _VERSION == "Lua 5.1" and not _CC_DISABLE_LUA51_FEATURES then
  150. local string_env = nativegetfenv(("").gsub)
  151. function getfenv( env )
  152. if env == nil then
  153. env = 2
  154. elseif nativetype( env ) == "number" and env > 0 then
  155. env = env + 1
  156. end
  157. local fenv = nativegetfenv(env)
  158. if fenv == string_env then
  159. --nativeerror( "Attempt to access string metatable", 2 )
  160. return nativegetfenv( 0 )
  161. else
  162. return fenv
  163. end
  164. end
  165. end
  166. end
  167.  
  168. -- Install lua parts of the os api
  169. function os.version()
  170. return "CraftOS 1.7"
  171. end
  172.  
  173. function os.pullEventRaw( sFilter )
  174. return coroutine.yield( sFilter )
  175. end
  176.  
  177. function os.pullEvent( sFilter )
  178. local eventData = { os.pullEventRaw( sFilter ) }
  179. if eventData[1] == "terminate" then
  180. error( "Terminated", 0 )
  181. end
  182. return table.unpack( eventData )
  183. end
  184.  
  185. -- Install globals
  186. function sleep( nTime )
  187. local timer = os.startTimer( nTime or 0 )
  188. repeat
  189. local sEvent, param = os.pullEvent( "timer" )
  190. until param == timer
  191. end
  192.  
  193. function write( sText )
  194. local w,h = term.getSize()
  195. local x,y = term.getCursorPos()
  196.  
  197. local nLinesPrinted = 0
  198. local function newLine()
  199. if y + 1 <= h then
  200. term.setCursorPos(1, y + 1)
  201. else
  202. term.setCursorPos(1, h)
  203. term.scroll(1)
  204. end
  205. x, y = term.getCursorPos()
  206. nLinesPrinted = nLinesPrinted + 1
  207. end
  208.  
  209. -- Print the line with proper word wrapping
  210. while string.len(sText) > 0 do
  211. local whitespace = string.match( sText, "^[ \t]+" )
  212. if whitespace then
  213. -- Print whitespace
  214. term.write( whitespace )
  215. x,y = term.getCursorPos()
  216. sText = string.sub( sText, string.len(whitespace) + 1 )
  217. end
  218.  
  219. local newline = string.match( sText, "^\n" )
  220. if newline then
  221. -- Print newlines
  222. newLine()
  223. sText = string.sub( sText, 2 )
  224. end
  225.  
  226. local text = string.match( sText, "^[^ \t\n]+" )
  227. if text then
  228. sText = string.sub( sText, string.len(text) + 1 )
  229. if string.len(text) > w then
  230. -- Print a multiline word
  231. while string.len( text ) > 0 do
  232. if x > w then
  233. newLine()
  234. end
  235. term.write( text )
  236. text = string.sub( text, (w-x) + 2 )
  237. x,y = term.getCursorPos()
  238. end
  239. else
  240. -- Print a word normally
  241. if x + string.len(text) - 1 > w then
  242. newLine()
  243. end
  244. term.write( text )
  245. x,y = term.getCursorPos()
  246. end
  247. end
  248. end
  249.  
  250. return nLinesPrinted
  251. end
  252.  
  253. function print( ... )
  254. local nLinesPrinted = 0
  255. local nLimit = select("#", ... )
  256. for n = 1, nLimit do
  257. local s = tostring( select( n, ... ) )
  258. if n < nLimit then
  259. s = s .. "\t"
  260. end
  261. nLinesPrinted = nLinesPrinted + write( s )
  262. end
  263. nLinesPrinted = nLinesPrinted + write( "\n" )
  264. return nLinesPrinted
  265. end
  266.  
  267. function printError( ... )
  268. local oldColour
  269. if term.isColour() then
  270. oldColour = term.getTextColour()
  271. term.setTextColour( colors.red )
  272. end
  273. print( ... )
  274. if term.isColour() then
  275. term.setTextColour( oldColour )
  276. end
  277. end
  278.  
  279. function read( _sReplaceChar, _tHistory, _fnComplete )
  280. term.setCursorBlink( true )
  281.  
  282. local sLine = ""
  283. local nHistoryPos
  284. local nPos = 0
  285. if _sReplaceChar then
  286. _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  287. end
  288.  
  289. local tCompletions
  290. local nCompletion
  291. local function recomplete()
  292. if _fnComplete and nPos == string.len(sLine) then
  293. tCompletions = _fnComplete( sLine )
  294. if tCompletions and #tCompletions > 0 then
  295. nCompletion = 1
  296. else
  297. nCompletion = nil
  298. end
  299. else
  300. tCompletions = nil
  301. nCompletion = nil
  302. end
  303. end
  304.  
  305. local function uncomplete()
  306. tCompletions = nil
  307. nCompletion = nil
  308. end
  309.  
  310. local w = term.getSize()
  311. local sx = term.getCursorPos()
  312.  
  313. local function redraw( _bClear )
  314. local nScroll = 0
  315. if sx + nPos >= w then
  316. nScroll = (sx + nPos) - w
  317. end
  318.  
  319. local cx,cy = term.getCursorPos()
  320. term.setCursorPos( sx, cy )
  321. local sReplace = (_bClear and " ") or _sReplaceChar
  322. if sReplace then
  323. term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) )
  324. else
  325. term.write( string.sub( sLine, nScroll + 1 ) )
  326. end
  327.  
  328. if nCompletion then
  329. local sCompletion = tCompletions[ nCompletion ]
  330. local oldText, oldBg
  331. if not _bClear then
  332. oldText = term.getTextColor()
  333. oldBg = term.getBackgroundColor()
  334. term.setTextColor( colors.white )
  335. term.setBackgroundColor( colors.gray )
  336. end
  337. if sReplace then
  338. term.write( string.rep( sReplace, string.len( sCompletion ) ) )
  339. else
  340. term.write( sCompletion )
  341. end
  342. if not _bClear then
  343. term.setTextColor( oldText )
  344. term.setBackgroundColor( oldBg )
  345. end
  346. end
  347.  
  348. term.setCursorPos( sx + nPos - nScroll, cy )
  349. end
  350.  
  351. local function clear()
  352. redraw( true )
  353. end
  354.  
  355. recomplete()
  356. redraw()
  357.  
  358. local function acceptCompletion()
  359. if nCompletion then
  360. -- Clear
  361. clear()
  362.  
  363. -- Find the common prefix of all the other suggestions which start with the same letter as the current one
  364. local sCompletion = tCompletions[ nCompletion ]
  365. sLine = sLine .. sCompletion
  366. nPos = string.len( sLine )
  367.  
  368. -- Redraw
  369. recomplete()
  370. redraw()
  371. end
  372. end
  373. while true do
  374. local sEvent, param = os.pullEvent()
  375. if sEvent == "char" then
  376. -- Typed key
  377. clear()
  378. sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  379. nPos = nPos + 1
  380. recomplete()
  381. redraw()
  382.  
  383. elseif sEvent == "paste" then
  384. -- Pasted text
  385. clear()
  386. sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  387. nPos = nPos + string.len( param )
  388. recomplete()
  389. redraw()
  390.  
  391. elseif sEvent == "key" then
  392. if param == keys.enter then
  393. -- Enter
  394. if nCompletion then
  395. clear()
  396. uncomplete()
  397. redraw()
  398. end
  399. break
  400.  
  401. elseif param == keys.left then
  402. -- Left
  403. if nPos > 0 then
  404. clear()
  405. nPos = nPos - 1
  406. recomplete()
  407. redraw()
  408. end
  409.  
  410. elseif param == keys.right then
  411. -- Right
  412. if nPos < string.len(sLine) then
  413. -- Move right
  414. clear()
  415. nPos = nPos + 1
  416. recomplete()
  417. redraw()
  418. else
  419. -- Accept autocomplete
  420. acceptCompletion()
  421. end
  422.  
  423. elseif param == keys.up or param == keys.down then
  424. -- Up or down
  425. if nCompletion then
  426. -- Cycle completions
  427. clear()
  428. if param == keys.up then
  429. nCompletion = nCompletion - 1
  430. if nCompletion < 1 then
  431. nCompletion = #tCompletions
  432. end
  433. elseif param == keys.down then
  434. nCompletion = nCompletion + 1
  435. if nCompletion > #tCompletions then
  436. nCompletion = 1
  437. end
  438. end
  439. redraw()
  440.  
  441. elseif _tHistory then
  442. -- Cycle history
  443. clear()
  444. if param == keys.up then
  445. -- Up
  446. if nHistoryPos == nil then
  447. if #_tHistory > 0 then
  448. nHistoryPos = #_tHistory
  449. end
  450. elseif nHistoryPos > 1 then
  451. nHistoryPos = nHistoryPos - 1
  452. end
  453. else
  454. -- Down
  455. if nHistoryPos == #_tHistory then
  456. nHistoryPos = nil
  457. elseif nHistoryPos ~= nil then
  458. nHistoryPos = nHistoryPos + 1
  459. end
  460. end
  461. if nHistoryPos then
  462. sLine = _tHistory[nHistoryPos]
  463. nPos = string.len( sLine )
  464. else
  465. sLine = ""
  466. nPos = 0
  467. end
  468. uncomplete()
  469. redraw()
  470.  
  471. end
  472.  
  473. elseif param == keys.backspace then
  474. -- Backspace
  475. if nPos > 0 then
  476. clear()
  477. sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  478. nPos = nPos - 1
  479. recomplete()
  480. redraw()
  481. end
  482.  
  483. elseif param == keys.home then
  484. -- Home
  485. if nPos > 0 then
  486. clear()
  487. nPos = 0
  488. recomplete()
  489. redraw()
  490. end
  491.  
  492. elseif param == keys.delete then
  493. -- Delete
  494. if nPos < string.len(sLine) then
  495. clear()
  496. sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
  497. recomplete()
  498. redraw()
  499. end
  500.  
  501. elseif param == keys["end"] then
  502. -- End
  503. if nPos < string.len(sLine ) then
  504. clear()
  505. nPos = string.len(sLine)
  506. recomplete()
  507. redraw()
  508. end
  509.  
  510. elseif param == keys.tab then
  511. -- Tab (accept autocomplete)
  512. acceptCompletion()
  513.  
  514. end
  515.  
  516. elseif sEvent == "term_resize" then
  517. -- Terminal resized
  518. w = term.getSize()
  519. redraw()
  520.  
  521. end
  522. end
  523.  
  524. local cx, cy = term.getCursorPos()
  525. term.setCursorBlink( false )
  526. term.setCursorPos( w + 1, cy )
  527. print()
  528.  
  529. return sLine
  530. end
  531.  
  532. loadfile = function( _sFile, _tEnv )
  533. local file = fs.open( _sFile, "r" )
  534. if file then
  535. local func, err = load( file.readAll(), fs.getName( _sFile ), "t", _tEnv )
  536. file.close()
  537. return func, err
  538. end
  539. return nil, "File not found"
  540. end
  541.  
  542. dofile = function( _sFile )
  543. local fnFile, e = loadfile( _sFile, _G )
  544. if fnFile then
  545. return fnFile()
  546. else
  547. error( e, 2 )
  548. end
  549. end
  550.  
  551. -- Install the rest of the OS api
  552. function os.run( _tEnv, _sPath, ... )
  553. local tArgs = { ... }
  554. local tEnv = _tEnv
  555. setmetatable( tEnv, { __index = _G } )
  556. local fnFile, err = loadfile( _sPath, tEnv )
  557. if fnFile then
  558. local ok, err = pcall( function()
  559. fnFile( table.unpack( tArgs ) )
  560. end )
  561. if not ok then
  562. if err and err ~= "" then
  563. printError( err )
  564. end
  565. return false
  566. end
  567. return true
  568. end
  569. if err and err ~= "" then
  570. printError( err )
  571. end
  572. return false
  573. end
  574.  
  575. local tAPIsLoading = {}
  576. function os.loadAPI( _sPath )
  577. local sName = fs.getName( _sPath )
  578. if tAPIsLoading[sName] == true then
  579. printError( "API "..sName.." is already being loaded" )
  580. return false
  581. end
  582. tAPIsLoading[sName] = true
  583.  
  584. local tEnv = {}
  585. setmetatable( tEnv, { __index = _G } )
  586. local fnAPI, err = loadfile( _sPath, tEnv )
  587. if fnAPI then
  588. local ok, err = pcall( fnAPI )
  589. if not ok then
  590. printError( err )
  591. tAPIsLoading[sName] = nil
  592. return false
  593. end
  594. else
  595. printError( err )
  596. tAPIsLoading[sName] = nil
  597. return false
  598. end
  599.  
  600. local tAPI = {}
  601. for k,v in pairs( tEnv ) do
  602. if k ~= "_ENV" then
  603. tAPI[k] = v
  604. end
  605. end
  606.  
  607. _G[sName] = tAPI
  608. tAPIsLoading[sName] = nil
  609. return true
  610. end
  611.  
  612. function os.unloadAPI( _sName )
  613. if _sName ~= "_G" and type(_G[_sName]) == "table" then
  614. _G[_sName] = nil
  615. end
  616. end
  617.  
  618. function os.sleep( nTime )
  619. sleep( nTime )
  620. end
  621.  
  622. local nativeShutdown = os.shutdown
  623. function os.shutdown()
  624. nativeShutdown()
  625. while true do
  626. coroutine.yield()
  627. end
  628. end
  629.  
  630. local nativeReboot = os.reboot
  631. function os.reboot()
  632. nativeReboot()
  633. while true do
  634. coroutine.yield()
  635. end
  636. end
  637.  
  638. -- Install the lua part of the HTTP api (if enabled)
  639. if http then
  640. local nativeHTTPRequest = http.request
  641.  
  642. local function wrapRequest( _url, _post, _headers )
  643. local ok, err = nativeHTTPRequest( _url, _post, _headers )
  644. if ok then
  645. while true do
  646. local event, param1, param2 = os.pullEvent()
  647. if event == "http_success" and param1 == _url then
  648. return param2
  649. elseif event == "http_failure" and param1 == _url then
  650. return nil, param2
  651. end
  652. end
  653. end
  654. return nil, err
  655. end
  656.  
  657. http.get = function( _url, _headers )
  658. return wrapRequest( _url, nil, _headers )
  659. end
  660.  
  661. http.post = function( _url, _post, _headers )
  662. return wrapRequest( _url, _post or "", _headers )
  663. end
  664.  
  665. http.request = function( _url, _post, _headers )
  666. local ok, err = nativeHTTPRequest( _url, _post, _headers )
  667. if not ok then
  668. os.queueEvent( "http_failure", _url, err )
  669. end
  670. return ok, err
  671. end
  672. end
  673.  
  674. -- Install the lua part of the FS api
  675. local tEmpty = {}
  676. function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs )
  677. bIncludeFiles = (bIncludeFiles ~= false)
  678. bIncludeDirs = (bIncludeDirs ~= false)
  679. local sDir = sLocation
  680. local nStart = 1
  681. local nSlash = string.find( sPath, "[/\\]", nStart )
  682. if nSlash == 1 then
  683. sDir = ""
  684. nStart = 2
  685. end
  686. local sName
  687. while not sName do
  688. local nSlash = string.find( sPath, "[/\\]", nStart )
  689. if nSlash then
  690. local sPart = string.sub( sPath, nStart, nSlash - 1 )
  691. sDir = fs.combine( sDir, sPart )
  692. nStart = nSlash + 1
  693. else
  694. sName = string.sub( sPath, nStart )
  695. end
  696. end
  697.  
  698. if fs.isDir( sDir ) then
  699. local tResults = {}
  700. if bIncludeDirs and sPath == "" then
  701. table.insert( tResults, "." )
  702. end
  703. if sDir ~= "" then
  704. if sPath == "" then
  705. table.insert( tResults, (bIncludeDirs and "..") or "../" )
  706. elseif sPath == "." then
  707. table.insert( tResults, (bIncludeDirs and ".") or "./" )
  708. end
  709. end
  710. local tFiles = fs.list( sDir )
  711. for n=1,#tFiles do
  712. local sFile = tFiles[n]
  713. if #sFile >= #sName and string.sub( sFile, 1, #sName ) == sName then
  714. local bIsDir = fs.isDir( fs.combine( sDir, sFile ) )
  715. local sResult = string.sub( sFile, #sName + 1 )
  716. if bIsDir then
  717. table.insert( tResults, sResult .. "/" )
  718. if bIncludeDirs and #sResult > 0 then
  719. table.insert( tResults, sResult )
  720. end
  721. else
  722. if bIncludeFiles and #sResult > 0 then
  723. table.insert( tResults, sResult )
  724. end
  725. end
  726. end
  727. end
  728. return tResults
  729. end
  730. return tEmpty
  731. end
  732.  
  733. -- Load APIs
  734. local bAPIError = false
  735. local tApis = fs.list( "rom/apis" )
  736. for n,sFile in ipairs( tApis ) do
  737. if string.sub( sFile, 1, 1 ) ~= "." then
  738. local sPath = fs.combine( "rom/apis", sFile )
  739. if not fs.isDir( sPath ) then
  740. if not os.loadAPI( sPath ) then
  741. bAPIError = true
  742. end
  743. end
  744. end
  745. end
  746.  
  747. if turtle then
  748. -- Load turtle APIs
  749. local tApis = fs.list( "rom/apis/turtle" )
  750. for n,sFile in ipairs( tApis ) do
  751. if string.sub( sFile, 1, 1 ) ~= "." then
  752. local sPath = fs.combine( "rom/apis/turtle", sFile )
  753. if not fs.isDir( sPath ) then
  754. if not os.loadAPI( sPath ) then
  755. bAPIError = true
  756. end
  757. end
  758. end
  759. end
  760. end
  761.  
  762. if pocket and fs.isDir( "rom/apis/pocket" ) then
  763. -- Load pocket APIs
  764. local tApis = fs.list( "rom/apis/pocket" )
  765. for n,sFile in ipairs( tApis ) do
  766. if string.sub( sFile, 1, 1 ) ~= "." then
  767. local sPath = fs.combine( "rom/apis/pocket", sFile )
  768. if not fs.isDir( sPath ) then
  769. if not os.loadAPI( sPath ) then
  770. bAPIError = true
  771. end
  772. end
  773. end
  774. end
  775. end
  776.  
  777. if commands and fs.isDir( "rom/apis/command" ) then
  778. -- Load command APIs
  779. if os.loadAPI( "rom/apis/command/commands" ) then
  780. -- Add a special case-insensitive metatable to the commands api
  781. local tCaseInsensitiveMetatable = {
  782. __index = function( table, key )
  783. local value = rawget( table, key )
  784. if value ~= nil then
  785. return value
  786. end
  787. if type(key) == "string" then
  788. local value = rawget( table, string.lower(key) )
  789. if value ~= nil then
  790. return value
  791. end
  792. end
  793. return nil
  794. end
  795. }
  796. setmetatable( commands, tCaseInsensitiveMetatable )
  797. setmetatable( commands.async, tCaseInsensitiveMetatable )
  798.  
  799. -- Add global "exec" function
  800. exec = commands.exec
  801. else
  802. bAPIError = true
  803. end
  804. end
  805.  
  806. if bAPIError then
  807. print( "Press any key to continue" )
  808. os.pullEvent( "key" )
  809. term.clear()
  810. term.setCursorPos( 1,1 )
  811. end
  812.  
  813. -- Set default settings
  814. settings.set( "shell.allow_startup", true )
  815. settings.set( "shell.allow_disk_startup", (commands == nil) )
  816. settings.set( "shell.autocomplete", true )
  817. settings.set( "edit.autocomplete", true )
  818. settings.set( "lua.autocomplete", true )
  819. settings.set( "list.show_hidden", false )
  820. if term.isColour() then
  821. settings.set( "bios.use_multishell", true )
  822. end
  823. if _CC_DEFAULT_SETTINGS then
  824. for sPair in string.gmatch( _CC_DEFAULT_SETTINGS, "[^,]+" ) do
  825. local sName, sValue = string.match( sPair, "([^=]*)=(.*)" )
  826. if sName and sValue then
  827. local value
  828. if sValue == "true" then
  829. value = true
  830. elseif sValue == "false" then
  831. value = false
  832. elseif sValue == "nil" then
  833. value = nil
  834. elseif tonumber(sValue) then
  835. value = tonumber(sValue)
  836. else
  837. value = sValue
  838. end
  839. if value ~= nil then
  840. settings.set( sName, value )
  841. else
  842. settings.unset( sName )
  843. end
  844. end
  845. end
  846. end
  847.  
  848. -- Load user settings
  849. if fs.exists( ".settings" ) then
  850. settings.load( ".settings" )
  851. end
  852.  
  853. -- Run the shell
  854. local ok, err = pcall( function()
  855. parallel.waitForAny(
  856. function()
  857. local sShell
  858. if term.isColour() and settings.get( "bios.use_multishell" ) then
  859. sShell = "rom/programs/advanced/multishell"
  860. else
  861. sShell = "rom/programs/shell"
  862. end
  863. os.run( {}, sShell )
  864. os.run( {}, "rom/programs/shutdown" )
  865. end,
  866. function()
  867. rednet.run()
  868. end )
  869. end )
  870.  
  871. -- If the shell errored, let the user read it.
  872. term.redirect( term.native() )
  873. if not ok then
  874. printError( err )
  875. pcall( function()
  876. term.setCursorBlink( false )
  877. print( "Press any key to continue" )
  878. os.pullEvent( "key" )
  879. end )
  880. end
  881.  
  882. -- End
  883. os.shutdown()
Add Comment
Please, Sign In to add comment