diff --git a/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md b/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md index 0566ab3c9..e14f8d277 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md @@ -12,6 +12,6 @@ This will allow you to call all of the functions provided by the [redstone](../i `rs.setOutput(require("sides").front, 15)` -**Important**: when working in the Lua interpreter, *do not* use `local`, as that will make the variables local to a single line of input. Meaning if you were to enter the lines above one after another in the interpreter, the third one would error, telling you that `rs` is a `nil` value. Why only on the third line, you ask? Because, for ease of testing, the interpreter tries to load unknown variables as libraries. So even though the assignment to `component` from the first line would nothing, the use of `component` on the second line would cause that library to be loaded and used. Libraries are not automatically used when using Lua scripts to keep memory usage low, because that's a limited resource. +**Important**: when working in the Lua interpreter, *do not* use `local`, as that will make the variables local to a single line of input. Meaning if you were to enter the lines above one after another in the interpreter, the third one would error, telling you that `rs` is a `nil` value. Why only on the third line, you ask? Because, for ease of testing, the interpreter tries to load unknown variables as libraries. So even though the assignment to `component` from the first line would do nothing, the use of `component` on the second line would cause that library to be loaded and used. Libraries are not automatically used when using Lua scripts to keep memory usage low, because that's a limited resource. OpenOS provides many custom libraries which can be used for many applications, from controlling and manipulating components attached to the [computer](computer.md), to reference APIs for colors used in bundled redstone control and [keyboard](../block/keyboard.md) keycodes. Custom libraries can be used within a Lua script by using the `require()` function, as above. Some custom libraries require specific components to work, such as the `internet` library requiring an [internet card](../item/internetCard.md). In that particular case it is even being provided by it, i.e. the library will show up once you install an internet card - technically speaking, it is contained on a small, read-only file system on the internet card. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/server1.md b/src/main/resources/assets/opencomputers/doc/en_US/item/server1.md index fa8c16556..00c354475 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/server1.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/server1.md @@ -2,7 +2,7 @@ ![Serves u right.](oredict:oc:server1) -Servers are a form of higher tier [computer](../general/computer.md). They can be configured by holding them in the hand and using them - like opening a backpack or Ender pouch, for example. The can also be configured after having been installed into a [rack](../block/rack.md) by activating them (aiming at the corresponding position on the front face on the [rack](../block/rack.md)). To operate, the server has to be placed inside a [rack](../block/rack.md). For more information see the [rack](../block/rack.md) entry. +Servers are a form of higher tier [computer](../general/computer.md). They can be configured by holding them in the hand and using them - like opening a backpack or Ender pouch, for example. Servers can also be configured after having been installed into a [rack](../block/rack.md) by activating them (aiming at the corresponding position on the front face on the [rack](../block/rack.md)). To operate, the server has to be placed inside a [rack](../block/rack.md). For more information see the [rack](../block/rack.md) entry. The tier 1 server is capable of taking the following components: - 1x tier 2 [CPU](cpu2.md) diff --git a/src/main/resources/assets/opencomputers/loot/openloader/.install b/src/main/resources/assets/opencomputers/loot/openloader/.install new file mode 100644 index 000000000..a2fc18674 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/openloader/.install @@ -0,0 +1 @@ +os.execute(install.from .. "/bin/opl-flash.lua") diff --git a/src/main/resources/assets/opencomputers/loot/openloader/bin/opl-flash.lua b/src/main/resources/assets/opencomputers/loot/openloader/bin/opl-flash.lua index a8de2204e..9ed64f54d 100644 --- a/src/main/resources/assets/opencomputers/loot/openloader/bin/opl-flash.lua +++ b/src/main/resources/assets/opencomputers/loot/openloader/bin/opl-flash.lua @@ -142,25 +142,25 @@ local term = require "term" local args, options = shell.parse(...) if options.h or options.help then - print("opl-flash [-hqr] [--label=EEPROMLabel]") - print(" --label= Set specified label for the EEPROM") - print(" -q --quiet Do not output anything, and don't ask if sure") - print(" -r --reboot Reboot after installing") - print(" -h --help Display this help") - return + print("opl-flash [-hqr] [--label=EEPROMLabel]") + print(" --label= Set specified label for the EEPROM") + print(" -q --quiet Do not output anything, and don't ask if sure") + print(" -r --reboot Reboot after installing") + print(" -h --help Display this help") + return end local say = not (options.q or options.quiet) and print or function()end say ("Do you really want to flash openloader to EEPROM("..tostring(#eeprom).." bytes)[Y/n]") -if options.q or options.quiet or io.read():lower() == "y" then - say("Flashing... Do not reboot now!") - component.eeprom.set(eeprom) - component.eeprom.setLabel((type(options.label) == "string" and options.label) or version) - if options.r or options.reboot then - computer.shutdown(true) - else - say("Done. you can reboot now") - end +if options.q or options.quiet or ((io.read() or "n").."y"):match("^%s*[Yy]") then + say("Flashing... Do not reboot now!") + component.eeprom.set(eeprom) + component.eeprom.setLabel((type(options.label) == "string" and options.label) or version) + if options.r or options.reboot then + computer.shutdown(true) + else + say("Done. you can reboot now") + end end diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/buffer.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/buffer.lua index 1a7595267..62c871110 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/buffer.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/buffer.lua @@ -158,10 +158,13 @@ function buffer:read(...) if type(format) == "number" then return readBytesOrChars(format) else - if type(format) ~= "string" or unicode.sub(format, 1, 1) ~= "*" then + local first_char_index = 1 + if type(format) ~= "string" then error("bad argument #" .. n .. " (invalid option)") + elseif unicode.sub(format, 1, 1) == "*" then + first_char_index = 2 end - format = unicode.sub(format, 2, 2) + format = unicode.sub(format, first_char_index, first_char_index) if format == "n" then return require("tools/advanced-buffering").readNumber(self, readChunk) elseif format == "l" then diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/process.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/process.lua index 15f362d26..1cca5e445 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/process.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/process.lua @@ -52,7 +52,8 @@ function process.load(path, env, init, name) io.stderr:write(path .. ": is a directory\n") return 126 end - io.stderr:write(path .. ": " .. reason .. "\n") + local handler = require("tools/programLocations") + handler.reportNotFound(path, reason) return 127 end os.setenv("_", program) diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/tools/programLocations.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/programLocations.lua new file mode 100644 index 000000000..9772e00ea --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/programLocations.lua @@ -0,0 +1,24 @@ +local computer = require("computer") +local lib = {} + +function lib.locate(path) + for _,lookup in ipairs(computer.getProgramLocations()) do + if lookup[1] == path then + return lookup[2] + end + end +end + +function lib.reportNotFound(path, reason) + checkArg(1, path, "string") + local loot = lib.locate(path) + if loot then + io.stderr:write("The program '" .. path .. "' is currently not installed. To install it:\n" .. + "1. Craft the '" .. loot .. "' floppy disk and insert it into this computer.\n" .. + "2. Run `install " .. loot .. "`") + elseif type(reason) == "string" then + io.stderr:write(path .. ": " .. reason .. "\n") + end +end + +return lib diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala index 63aedd01b..3265b6308 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala @@ -83,8 +83,6 @@ object ModOpenComputers extends ModProxy { api.IMC.registerProgramDiskLabel("md5sum", "data", "Lua 5.2", "Lua 5.3", "LuaJ") api.IMC.registerProgramDiskLabel("sha256sum", "data", "Lua 5.2", "Lua 5.3", "LuaJ") api.IMC.registerProgramDiskLabel("refuel", "generator", "Lua 5.2", "Lua 5.3", "LuaJ") - api.IMC.registerProgramDiskLabel("pastebin", "internet", "Lua 5.2", "Lua 5.3", "LuaJ") - api.IMC.registerProgramDiskLabel("wget", "internet", "Lua 5.2", "Lua 5.3", "LuaJ") api.IMC.registerProgramDiskLabel("irc", "irc", "Lua 5.2", "Lua 5.3", "LuaJ") api.IMC.registerProgramDiskLabel("maze", "maze", "Lua 5.2", "Lua 5.3", "LuaJ") api.IMC.registerProgramDiskLabel("arp", "network", "Lua 5.2", "Lua 5.3", "LuaJ")