Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if _G.bootloaded == true then return end -- ensures that startup runs only once
- --------------------------------------------------------------------------------
- --- Simplest Bootloader for ComputerCraft 1.6
- -- @version 0.4-beta
- -- @author Shefla
- -- @license MIT
- -- @changelog
- -- 0.1 Initial version adapted from Geforce Fan's TLCO concept
- -- 0.2 Added rednet.run spoofing to avoid forced autostart
- -- Switched from terminate event to modem_message to trigger printError
- -- 0.3 Public release, added comments to config section
- -- 0.4 Removed hardcoded CraftOS version from default config (use os.version)
- --------------------------------------------------------------------------------
- -- Title of the bootloader screen
- local title = 'Simplest Bootloader v0.4-beta'
- -- Bootable entries configuration
- -- If there is only one entry it is booted without displaying menu
- local entries = {
- {
- -- name is used when displaying menu
- name = os.version()
- -- boot function executed on selection (shell API not available)
- , boot = function ()
- -- from bios.lua
- parallel.waitForAny(
- function ()
- os.run({}, term.isColor()
- and '/rom/programs/advanced/multishell'
- or '/rom/programs/shell'
- )
- end
- , function () rednet.run() end
- )
- end
- }
- , {
- name = os.version()..' (no rednet, no multishell)'
- , boot = function ()
- term.redirect(term.native())
- os.run({ multishell = false }, '/rom/programs/shell')
- end
- }
- }
- --8<-- Probably no need to edit below --8<--------------------------------------
- local nativePrintError = _G.printError
- local nativeRednetRun = _G.rednet.run
- function _G.rednet.run () error('', 0) end
- function _G.printError ()
- local entry
- _G.bootloaded = true
- _G.printError = nativePrintError
- _G.rednet.run = nativeRednetRun
- if #entries == 1 then entry = entries[1]
- else
- term.clear()
- term.setCursorPos(1, 1)
- print(title)
- print()
- for index, entry in pairs(entries) do
- print('F'..index..': '..entry.name)
- end
- while true do
- local event, key = os.pullEvent('key')
- local index = key - 58
- if entries[index] ~= nil then
- entry = entries[index]
- break
- end
- end
- end
- print('Launching '..entry.name)
- local ok, err = pcall(entry.boot)
- if not ok then
- printError(err)
- print('Press any key to continue')
- os.pullEvent('key')
- end
- os.shutdown()
- end
- os.queueEvent('modem_message')
Advertisement
Add Comment
Please, Sign In to add comment