From e5c18fea6b43eeb00fb6a43a53d9f4e35549768a Mon Sep 17 00:00:00 2001 From: payonel Date: Wed, 26 Oct 2016 22:33:07 -0700 Subject: [PATCH 1/6] lua 5.3 allows no * prefix in io.read --- .../assets/opencomputers/loot/openos/lib/buffer.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 From 280bebb4dca9de56e30bbb8071c305a7807bf38d Mon Sep 17 00:00:00 2001 From: payonel Date: Fri, 28 Oct 2016 10:02:49 -0700 Subject: [PATCH 2/6] grammar corrections --- .../resources/assets/opencomputers/doc/en_US/general/lua.md | 2 +- .../resources/assets/opencomputers/doc/en_US/item/server1.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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) From c875381d40e2094b90e409a4c44b5ff259161e96 Mon Sep 17 00:00:00 2001 From: payonel Date: Wed, 26 Oct 2016 23:07:07 -0700 Subject: [PATCH 3/6] wget and pastebin are now core to openos install --- .../li/cil/oc/integration/opencomputers/ModOpenComputers.scala | 2 -- 1 file changed, 2 deletions(-) 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 097e93f5d..164d977bc 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala @@ -80,8 +80,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") From e5d2b0051fd2210acc82688735d03146241b6dfb Mon Sep 17 00:00:00 2001 From: payonel Date: Wed, 26 Oct 2016 23:37:34 -0700 Subject: [PATCH 4/6] simple error reporting and message to craft install disk if user tries to use program known to computer.getProgramLocations() --- .../opencomputers/loot/openos/lib/process.lua | 3 ++- .../openos/lib/tools/programLocations.lua | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/assets/opencomputers/loot/openos/lib/tools/programLocations.lua 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..1f165d60c --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/programLocations.lua @@ -0,0 +1,23 @@ +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) + 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 .. "`") + else + io.stderr:write(path .. ": " .. reason .. "\n") + end +end + +return lib From 83129f21ac72c5cc025235cb7a4824a5b2c757fc Mon Sep 17 00:00:00 2001 From: payonel Date: Tue, 1 Nov 2016 22:44:52 -0700 Subject: [PATCH 5/6] check args --- .../opencomputers/loot/openos/lib/tools/programLocations.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 1f165d60c..9772e00ea 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/tools/programLocations.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/programLocations.lua @@ -10,12 +10,13 @@ function lib.locate(path) 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 .. "`") - else + elseif type(reason) == "string" then io.stderr:write(path .. ": " .. reason .. "\n") end end From c80943c9ce447a14be66471a167afc4e34be17c2 Mon Sep 17 00:00:00 2001 From: payonel Date: Wed, 2 Nov 2016 21:30:35 -0700 Subject: [PATCH 6/6] make openloader installer compatable with openos install tool --- .../opencomputers/loot/openloader/.install | 1 + .../loot/openloader/bin/opl-flash.lua | 30 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/assets/opencomputers/loot/openloader/.install 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