Skip to content

Commit

Permalink
Add example on how to use debug features
Browse files Browse the repository at this point in the history
  • Loading branch information
dwursteisen committed Dec 14, 2023
1 parent 28f8a30 commit bf7e08c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DebugLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction(
return tiny
}

@TinyFunction("Enable or disable debug feature.")
@TinyFunction("Enable or disable debug feature.", example = DEBUG_ENABLED_EXAMPLE)
internal inner class enabled : OneArgFunction() {
@TinyCall("Enable or disable debug by passing true to enable, false to disable.")
override fun call(@TinyArg("enabled") arg: LuaValue): LuaValue {
Expand All @@ -87,7 +87,7 @@ class DebugLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction(
}
}

@TinyFunction("Display a table.")
@TinyFunction("Display a table.", example = DEBUG_EXAMPLE)
internal inner class table : OneArgFunction() {
@TinyCall("Display a table.")
override fun call(@TinyArg("table") arg: LuaValue): LuaValue {
Expand All @@ -107,7 +107,7 @@ class DebugLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction(
}
}

@TinyFunction("Log a message on the screen.")
@TinyFunction("Log a message on the screen.", example = DEBUG_EXAMPLE)
internal inner class log : TwoArgFunction() {

@TinyCall("Log a message on the screen.")
Expand All @@ -122,7 +122,7 @@ class DebugLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction(
override fun call(@TinyArg("str") arg: LuaValue): LuaValue = super.call(arg)
}

@TinyFunction("Draw a rectangle on the screen")
@TinyFunction("Draw a rectangle on the screen", example = DEBUG_ENABLED_EXAMPLE)
internal inner class rect : LibFunction() {

@TinyCall("Draw a debug rectangle.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.minigdx.tiny.lua

//language=Lua
const val DEBUG_EXAMPLE = """
function _update()
local pos = ctrl.touch()
debug.table(pos)
debug.log("frame "..tiny.frame)
end
function _draw()
gfx.cls()
-- draw the mouse position.
local pos = ctrl.touch()
shape.line(pos.x - 2, pos.y, pos.x + 2, pos.y, 3)
shape.line(pos.x, pos.y - 2, pos.x, pos.y + 2, 3)
end
"""

//language=Lua
const val DEBUG_ENABLED_EXAMPLE = """
function _init()
switch = true
end
function _update()
local pos = ctrl.touch()
debug.rect(pos.x, pos.y, 16, 16)
if ctrl.touched(0) then
switch = not switch
debug.enabled(switch)
end
debug.log("debug ".. tostring(switch))
end
function _draw()
gfx.cls()
-- draw the mouse position.
local pos = ctrl.touch()
shape.line(pos.x - 2, pos.y, pos.x + 2, pos.y, 3)
shape.line(pos.x, pos.y - 2, pos.x, pos.y + 2, 3)
if switch then
print("debug enabled", 10, 40)
else
print("debug disabled", 10, 40)
end
end
"""

0 comments on commit bf7e08c

Please sign in to comment.