Display string/number keys same as values

This commit is contained in:
Fingercomp 2021-08-21 07:23:45 +07:00
parent 3fbc17c603
commit efffa2b41d
No known key found for this signature in database
GPG Key ID: BBC71CEE45D86E37
2 changed files with 16 additions and 27 deletions

@ -1 +1 @@
Subproject commit b9af29bb93878bb49079026ebc011d832dd61e4b Subproject commit ca8a2de2c7994f6a8c57f7d4433991b170b9935a

View File

@ -11,7 +11,6 @@ import ocelot.desktop.ui.layout.LinearLayout
import ocelot.desktop.ui.widget._ import ocelot.desktop.ui.widget._
import ocelot.desktop.ui.widget.window.BasicWindow import ocelot.desktop.ui.widget.window.BasicWindow
import ocelot.desktop.util.Orientation import ocelot.desktop.util.Orientation
import org.apache.commons.text.StringEscapeUtils
import totoro.ocelot.brain.entity.machine.luac._ import totoro.ocelot.brain.entity.machine.luac._
import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ArrayBuffer
@ -370,16 +369,7 @@ class DebuggerWindow(computerNode: ComputerNode) extends BasicWindow {
extends LuaValueView(name) extends LuaValueView(name)
{ {
children :+= new Label { children :+= new Label {
override def text: String = number match { override def text: String = number.toString
case LuaValue.Number.Integer(value) => value.toString
case LuaValue.Number.Double(value) => value match {
case v if v.isPosInfinity => "inf"
case v if v.isNegInfinity => "-inf"
case v if v.isNaN => if ((java.lang.Double.doubleToRawLongBits(v) >>> 63) == 0x0) "nan" else "-nan"
case v => v.toString
}
}
override def color: Color = ColorScheme("ComputerAddress") override def color: Color = ColorScheme("ComputerAddress")
} }
} }
@ -694,16 +684,10 @@ class DebuggerWindow(computerNode: ComputerNode) extends BasicWindow {
private def luaValueToTableKey(value: LuaValue): Option[String] = { private def luaValueToTableKey(value: LuaValue): Option[String] = {
Some(value match { Some(value match {
case LuaValue.Nil => case LuaValue.Nil => "[nil]"
"[nil]" case LuaValue.Boolean(v) => if (v) "[true]" else "[false]"
case LuaValue.Boolean(v) => case v: LuaValue.Number => s"[$v]"
if (v) "[true]" else "[false]" case LuaValue.String(s) => stringToPathComponent(s)
case LuaValue.Number.Integer(v) =>
s"[$v]"
case LuaValue.Number.Double(v) =>
s"[$v]"
case s: LuaValue.String =>
stringToPathComponent(s.toUtf8String)
case _ => return None case _ => return None
}) })
} }
@ -722,11 +706,11 @@ class DebuggerWindow(computerNode: ComputerNode) extends BasicWindow {
} }
} }
private def stringToPathComponent(s: String): String = { private def stringToPathComponent(s: List[Byte]): String = {
if (isValidIdent(s)) if (isValidIdent(s))
s"$s" new String(s.toArray)
else else
s"[${'"' + StringEscapeUtils.escapeJava(s) + '"'}]" "[" + escapeLuaString(s) + "]"
} }
private def localNameToPathComponent(s: String): String = { private def localNameToPathComponent(s: String): String = {
@ -767,8 +751,13 @@ class DebuggerWindow(computerNode: ComputerNode) extends BasicWindow {
Iterator(Some(what), nameWhat).flatten.mkString(" ") Iterator(Some(what), nameWhat).flatten.mkString(" ")
} }
private def isValidIdent(str: String): Boolean = { private def isValidIdent(str: List[Byte]): Boolean = {
str.matches("[a-zA-Z_][a-zA-Z0-9_]*") def isAlpha(c: Byte): Boolean = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
def isNumeric(c: Byte): Boolean = '0' <= c && c <= '9'
def checkFirstByte(c: Byte): Boolean = isAlpha(c) || c == '_'
def checkTailByte(c: Byte): Boolean = checkFirstByte(c) || isNumeric(c)
str.headOption.exists(checkFirstByte) && str.tail.forall(checkTailByte)
} }
private def clearStackFrames(): Unit = { private def clearStackFrames(): Unit = {