Skip to content

Commit

Permalink
Update debug.console to log tables
Browse files Browse the repository at this point in the history
  • Loading branch information
dwursteisen committed Jan 31, 2024
1 parent d298859 commit 02f2a9e
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private class DebugShape {
val color = args.arg(3)
return listOf(a.get("x"), a.get("y"), b.get("x"), b.get("y"), color)
}

else -> {
null
}
Expand All @@ -103,6 +104,7 @@ private class DebugShape {
val color = args.arg(3)
return listOf(a, b, color)
}

2 -> {
val a = args.arg(1)
val b = args.arg(2)
Expand All @@ -112,10 +114,12 @@ private class DebugShape {
listOf(a, b, LuaValue.NIL)
}
}

1 -> {
val a = args.arg(1)
return listOf(a.get("x"), a.get("y"), LuaValue.NIL)
}

else -> {
null
}
Expand Down Expand Up @@ -204,9 +208,20 @@ class DebugLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction(
internal inner class console : OneArgFunction() {
@TinyCall("Log a message into the console.")
override fun call(@TinyArg("str") arg: LuaValue): LuaValue {
println(arg)
val str = formatValue(arg)
println(str)
return NIL
}

private fun formatValue(arg: LuaValue): String = if (arg.istable()) {
val table = arg as LuaTable
val keys = table.keys()
val str = keys.map { it.optjstring("nil") + ":" + formatValue(table.get(it)) }
.joinToString(" ")
"table[$str]"
} else {
arg.toString()
}
}

@TinyFunction("Draw a rectangle on the screen", example = DEBUG_ENABLED_EXAMPLE)
Expand Down

0 comments on commit 02f2a9e

Please sign in to comment.