-
Notifications
You must be signed in to change notification settings - Fork 119
Object Functions: Debugging Tools
David Roberts edited this page Jan 15, 2017
·
4 revisions
-
benchmark(expr)
— Executes expr in a benchmark harness and returns a string describing its benchmark performance -
debug(...)
— outputs arguments to the console -
debug_chart(string id, decimal value)
— plots a sample in a graph -
debug_console()
— provides an interactive debugging console. Can also be opened with ctrl-d. -
debug_fn(msg, expr)
— evaluates and returns expr. Will print 'msg' to stderr if it's printable, or execute it if it's an executable command. -
debug_rect(int x, int y, (optional)int w=1, (optional) int h=1)
— Draws, for one frame, a rectangle on the level -
disassemble(function) -> string
— Return a human-readable listing of the Anura virtual machine bytecode. Example:
can_jump: "def() -> bool
bool(is_standing and (animation not in ['interact', 'fall', 'jump', 'start_jump']) or
//after frogatto starts falling off a ledge, give the player a little grace in allowing them to still initiate a jump.
animation = 'fall' and _cycles_since_last_touching_ground < postjump_grace_period)",
when run through disassemble(level.player.can_jump)
, yeilds
' 0: OP_CONSTANT 0 ( "@eval (UNSERIALIZABLE_OBJECT N10game_logic12_GLOBAL__N_113bool_functionE)" )
2: OP_LOOKUP 89
4: OP_JMP_UNLESS 7 ( -> 12)
6: OP_POP
7: OP_LOOKUP 11
9: OP_CONSTANT 1 ( ["interact","fall","jump","start_jump"] )
11: OP_NOT_IN
12: OP_JMP_IF 15 ( -> 28)
14: OP_POP
15: OP_LOOKUP 11
17: OP_CONSTANT 2 ( "fall" )
19: OP(=)
20: OP_JMP_UNLESS 7 ( -> 28)
22: OP_POP
23: OP_LOOKUP 437
25: OP_LOOKUP 533
27: OP(<)
28: OP_CALL_BUILTIN 1
'
-
dump(x)
— Equivalent todebug_fn(x, x)
. Essentially a no-op code-wise, it prints whatever x is to console and returns x. -
dump2(x, y)
— Equivalent todebug_fn([x, y], y)
. Likedump()
, dump2 is also a no-op for your logic. However, now you can include an identifying string before the stuff to be dumped so you can actually tell which dump function is dumping what data. -
performance()
— returns an object with current performance stats -
plot_x(int x)
— plots a vertical debug line at the given position -
plot_y(int x)
— plots a horizontal debug line at the given position -
pp(_)
— Removed in 1.4 in favour of lib.debug.pp. Pretty-print. Returns a human-readable string describing the data structure passed in. Despite the name, does not actually print the string. Lossy, abbreviates long lists/maps, doesn't expand many objects. Does indentation. Was designed to, where debug() shows you the data of a structure, show you the structure of the structure. -
objects_known_to_gc() -> [objects]
— Return a list of all objects. Can be compared to level.chars to detect memory leaks and profile lifetimes. -
report()
— Write a key and a value into [custom] in the stats. -
instrument(string name, commands ffl) -> int
— Has no effect on the ffl passed in, but prints how long it took to run. (Search for "Instrument:" to find the output.)
More help can be found via chat in Frogatto's Discord server, or by posting on the forums. This wiki is not a complete reference. Thank you for reading! You're the best. 🙂