refactor: convert IO from singleton instance to static class with metaclass native methods

Replace the global `io` singleton object with a static `IO` class, moving the `write` native from the instance to the metaclass. Update all benchmark, example, and test files to use `IO.write()` instead of `io.write()`.
This commit is contained in:
Bob Nystrom
2013-12-22 03:25:09 +00:00
parent 1a77a43fa0
commit 8bb1a94a25
119 changed files with 532 additions and 536 deletions
+12 -12
View File
@@ -1,24 +1,24 @@
// Returns characters (as strings).
io.write("abcd"[0]) // expect: a
io.write("abcd"[1]) // expect: b
io.write("abcd"[2]) // expect: c
io.write("abcd"[3]) // expect: d
IO.write("abcd"[0]) // expect: a
IO.write("abcd"[1]) // expect: b
IO.write("abcd"[2]) // expect: c
IO.write("abcd"[3]) // expect: d
// Allows indexing backwards from the end.
io.write("abcd"[-4]) // expect: a
io.write("abcd"[-3]) // expect: b
io.write("abcd"[-2]) // expect: c
io.write("abcd"[-1]) // expect: d
IO.write("abcd"[-4]) // expect: a
IO.write("abcd"[-3]) // expect: b
IO.write("abcd"[-2]) // expect: c
IO.write("abcd"[-1]) // expect: d
// Handle out of bounds.
// TODO: Should halt the fiber or raise an error somehow.
io.write("abcd"[4]) // expect: null
io.write("abcd"[-5]) // expect: null
IO.write("abcd"[4]) // expect: null
IO.write("abcd"[-5]) // expect: null
// Handle wrong argument type.
// TODO: Should halt the fiber or raise an error somehow.
io.write("abcd"[true]) // expect: null
IO.write("abcd"[true]) // expect: null
// Handle non-integer index.
// TODO: Should halt the fiber or raise an error somehow.
io.write("abcd"[1.5]) // expect: null
IO.write("abcd"[1.5]) // expect: null