proper error handling in ROMBASIC

Former-commit-id: b5bd084e6807c765cdd6d3ffff1b1628321b9c6a
Former-commit-id: 55c3bb3cd56c7867809c0819f178aeebf1e46676
This commit is contained in:
Song Minjae
2016-09-22 18:16:38 +09:00
parent 6caae90d7e
commit 433f27bef2
24 changed files with 208 additions and 137 deletions

View File

@@ -38,6 +38,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
globals["fs"]["open"] = OpenFile(computer) //CC compliant
globals["fs"]["parent"] = GetParentDir(computer)
// fs.dofile defined in ROMLIB
// fs.fetchText defined in ROMLIB
}
companion object {
@@ -300,7 +301,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
}
catch (e: FileNotFoundException) {
e.printStackTrace()
throw LuaError("$path: No such file.")
throw LuaError("$path: no such file.")
}
}
"rb" -> {
@@ -312,7 +313,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
}
catch (e: FileNotFoundException) {
e.printStackTrace()
throw LuaError("$path: No such file.")
throw LuaError("$path: no such file.")
}
}
"w", "a" -> {
@@ -325,7 +326,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
}
catch (e: FileNotFoundException) {
e.printStackTrace()
throw LuaError("$path: Is a directory.")
throw LuaError("$path: is a directory.")
}
}
"wb", "ab" -> {
@@ -338,7 +339,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
}
catch (e: FileNotFoundException) {
e.printStackTrace()
throw LuaError("$path: Is a directory.")
throw LuaError("$path: is a directory.")
}
}
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.virtualcomputer.luaapi
import li.cil.repack.org.luaj.vm2.Globals
import li.cil.repack.org.luaj.vm2.LuaFunction
import li.cil.repack.org.luaj.vm2.LuaTable
import li.cil.repack.org.luaj.vm2.LuaValue
import li.cil.repack.org.luaj.vm2.lib.OneArgFunction
@@ -61,9 +62,14 @@ internal class HostAccessProvider(globals: Globals, computer: BaseTerrarumComput
}
}
class NativeOpenInput(val term: Teletype) : ZeroArgFunction() {
class NativeOpenInput(val term: Teletype) : LuaFunction() {
override fun call(): LuaValue {
term.openInput()
term.openInput(true)
return LuaValue.NONE
}
override fun call(echo: LuaValue): LuaValue {
term.openInput(if (echo.checkint() == 1) false else true)
return LuaValue.NONE
}
}

View File

@@ -32,11 +32,15 @@ internal class Term(globals: Globals, term: Teletype) {
globals["term"]["resetColour"] = Term.ResetColour(term)
globals["term"]["clear"] = Term.Clear(term)
globals["term"]["clearLine"] = Term.ClearLine(term)
globals["term"]["setCursor"] = Term.SetCursor(term)
globals["term"]["getCursor"] = Term.GetCursorPos(term)
globals["term"]["getX"] = Term.GetCursorX(term)
globals["term"]["getY"] = Term.GetCursorY(term)
globals["term"]["setX"] = Term.SetCursorX(term)
globals["term"]["setY"] = Term.SetCursorY(term)
globals["term"]["blink"] = Term.SetCursorBlink(term)
globals["term"]["size"] = Term.GetSize(term)
globals["term"]["height"] = Term.GetHeight(term)
globals["term"]["isCol"] = Term.IsColour(term)
globals["term"]["setForeCol"] = Term.SetForeColour(term)
globals["term"]["setBackCol"] = Term.SetBackColour(term)
@@ -100,21 +104,21 @@ internal class Term(globals: Globals, term: Teletype) {
class EmitRaw(val term: Terminal) : ThreeArgFunction() {
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
term.emitChar(p0.checkint(), x.checkint(), y.checkint())
term.emitChar(p0.checkint(), x.checkint() - 1, y.checkint() - 1)
return LuaValue.NONE
}
}
class Emit(val term: Terminal) : ThreeArgFunction() {
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
term.emitChar(p0.checkint().toChar(), x.checkint(), y.checkint())
term.emitChar(p0.checkint().toChar(), x.checkint() - 1, y.checkint() - 1)
return LuaValue.NONE
}
}
class EmitString(val term: Terminal) : ThreeArgFunction() {
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
term.emitString(p0.checkIBM437(), x.checkint(), y.checkint())
term.emitString(p0.checkIBM437(), x.checkint() - 1, y.checkint() - 1)
return LuaValue.NONE
}
}
@@ -140,14 +144,6 @@ internal class Term(globals: Globals, term: Teletype) {
}
}
/** term.setCursorPos(number x, number y), One-based */
class SetCursorPos(val term: Terminal) : TwoArgFunction() {
override fun call(x: LuaValue, y: LuaValue): LuaValue {
term.setCursor(x.checkint() - 1, y.checkint() - 1)
return LuaValue.NONE
}
}
/** term.setCursorPos(number x) */
class MoveCursor(val tty: Teletype) : OneArgFunction() {
override fun call(p0: LuaValue): LuaValue {
@@ -157,6 +153,13 @@ internal class Term(globals: Globals, term: Teletype) {
}
}
class SetCursor(val term: Terminal) : TwoArgFunction() {
override fun call(x: LuaValue, y: LuaValue): LuaValue {
term.setCursor(x.checkint() - 1, y.checkint() - 1)
return LuaValue.NONE
}
}
/** One-based */
class GetCursorPos(val term: Terminal) : VarArgFunction() {
override fun invoke(args: Varargs?): Varargs {
@@ -177,6 +180,20 @@ internal class Term(globals: Globals, term: Teletype) {
}
}
class SetCursorX(val term: Terminal) : OneArgFunction() {
override fun call(p0: LuaValue): LuaValue {
term.setCursor(p0.checkint() - 1, term.cursorY)
return LuaValue.NONE
}
}
class SetCursorY(val term: Terminal) : OneArgFunction() {
override fun call(p0: LuaValue): LuaValue {
term.setCursor(term.cursorX - 1, p0.checkint())
return LuaValue.NONE
}
}
/** term.setCursorBlink(boolean bool) */
class SetCursorBlink(val term: Terminal) : OneArgFunction() {
override fun call(p0: LuaValue): LuaValue {
@@ -198,6 +215,12 @@ internal class Term(globals: Globals, term: Teletype) {
}
}
class GetHeight(val terminal: Terminal) : ZeroArgFunction() {
override fun call(): LuaValue {
return LuaValue.valueOf(terminal.height)
}
}
class IsColour(val term: Terminal) : ZeroArgFunction() {
override fun call(): LuaValue {
return LuaValue.valueOf(term.coloursCount > 4)