RDB

Description

Rstcxk's debugger 🔗

A powerful debugging mod. Featuring:

  • Inspector tool - Easily inspect nodes/mobs
  • Syntax highlighted pretty printers
  • Refernces to dumped objects - Can be inspected again. Easily find where a position is
  • Adnotations - Adnotate values, so they're easier to read. I.e. printing facedir
  • Table printer - create nice looking ASCII tables
  • REPL - basically breakpoints
  • Recipe creator - Easily make crafting recipes with a GUI

You need to add rdb to trusted mods. This mod exposes the debug table globally, make sure you trust all installed mods

This mod is best expeierienced while using luanti in a terminal. Things aren't printed in the chat

References 🔗

References are a core concept in RDB. Basically, every table/ObjRef or a long string emits a reference when logged

Take for example this print

(Its a bit hard to read now because lack of color. In game it will all be highlighted)

RDB: 20:12:04 T000113: @NODE:mcl_trees:tree_oak {
	@3 <metatable>,
	after_destruct = @4 <function: 0x7fa318532880>,
	description = "Oak Log\nFlammable",
	_doc_items_hidden = false,
	_doc_items_longdesc = "The trunk of a Oak tree.",
	groups = @5 {
		axey = 1,
		axey_dig = 12,
		flammable = 3,
		solid = 1,
	},
	is_ground_content = false,
	_mcl_burntime = 15,
	_mcl_cooking_output = "mcl_core:charcoal_lump",
	_mcl_crafting_output = @6 {
		single = @7 {output = "mcl_trees:wood_oak 4", },
		square2 = @8 {output = "mcl_trees:bark_oak 3", },
	},
	_mcl_hardness = 2,
	_mcl_stripped_variant = "mcl_trees:stripped_oak",
	mod_origin = "mcl_core",
	name = "mcl_trees:tree_oak",
	_on_axe_place = @API:mcl_trees:strip_tree <function: 0x7fa38bb1ecc0>,
	on_construct = @9 <function: 0x7fa38b38f210>,
	on_place = @API:mcl_util:rotate_axis <function: 0x7fa3886afe70>,
	on_rotate = @API:screwdriver:rotate_3way <function: 0x7fa38b2c8ac0>,
	paramtype2 = "facedir",
	sounds = @10 {
		dig = @11 {gain = 0.4, name = "default_dig_choppy", },
		dug = @12 {gain = 1, name = "default_wood_footstep", },
		footstep = @13 {gain = 0.15, name = "default_wood_footstep", },
		place = @14 {gain = 1, name = "default_place_node_hard", },
	},
	tiles = @15 {
		"default_tree_top.png",
		"default_tree_top.png^[transformFY",
		"default_tree.png",
	},
	_tt_original_description = "Oak Log",
	type = "node",
}

Besides every table you can see something like @5. This is a reference, you can use it to tell when two tables are actually the same table, or to inspect them afterwards via commands

/rdb 5

Will print the value with reference 5 (The @ is omitted when writing commands)

In addition, if the refernce points a vector. You can draw a line that points straight to it

/rdb_line 5

And lastly. You might have noticed that not every reference is just a number. Some references are named, like the on_place callback. It has refernces API:mcl_util:rotate_axis. This makes reading the dump a bit easier, and lets you know that the function is actually defined elsewhere, so you know where to look

Named refernces include:

  • NODE:<node name> - the node's definition
  • NODE:<node name>:<func> - A function in the node's definition
  • API:<mod name>:<func> - Mod's public facing API
  • API:core:<func> - Engine's api

A side effect of this is that you can easily check node definitions. Simply do:

/rdb NODE:mcl_core:dirt

Inspector 🔗

Punch any mob/node with the inspector and it will print information in the terminal

  • node - the technical name and param2. Metadata/Inventory are also printed if present
  • objects - print the object's name. Also dumps the lua entity if present

Usage 🔗

Here are useful debugging functions

rdb(...), rdb.log(...) 🔗

Pretty prints the given values

rdb.l(), rdb.locals() 🔗

Prints the local variables (excluding upvalues)

rdb.u(), rdb.upvalues() 🔗

Prints upvalues

rdb.t(), rdb.traceback() 🔗

Prints the traceback

rdb.b, rdb.repl() 🔗

Stops executing and enters REPL mode. Basically a breakpoint. You can write arbitrary lua in the terminal, and it will print the results. You can write lua standalone expressions

Inputting these has special behaviour:

  • cont, !, !c - exits REPL mode, resumes execution
  • !e - exits the world
  • !l - prints all the local variables
  • !u - prints all the upvalues

Local variables defined in REPL have a lifetime of a single line. Basically, if you want to define a variable there, define a global instead

If you try to exit the world while REPL is active, you will need to first exit it (cont)

rdb.logc(should_print, ...) 🔗

Similar to rdb.log() but only prints when should_print is true

rdb.node(node) 🔗

Adnotates table node to be interpreted as a node by RDB. When printing, it will look nicer

rdb.facedir(facedir) 🔗

Adnotates a number facedir to be interpreted by RDB as a facedir. When printing, it will display the value, the pointing axis, and rotation around it

rdb.dict_length(t) 🔗

Returns the length of t. This is functions is useful when you want to know how big a table is, sometimes #t is insufficient, since it doesn't count the hash part of the table

rdb.log_detalic(...) 🔗

Prints values in details. It doesn't cut off strings when they get too long

rdb.dump(value) 🔗

Drop in replacement for engine's dump(), except it uses RDB's printer, which will encode references

Doesn't do color highlighting

rdb.info() 🔗

Prints info about the current function. Like where its defined or the current line

Tables 🔗

RDB can print nice ASCII tables. This is sometimes useful

local tab = {
    {
        id = 1,
        name = "Joe",
        debt = 20000
    },
    {
        id = 2,
        name = "Little timmy",
        debt = 45000
    },
    {
        id = 3,
        name = "Blue collar connor",
        debt = 0
    },
    {
        id = 4,
        name = "USA",
        debt = 40363274597067
    },
}

-- Prints a table. The columns are ordered alphabetically
rdb.tab(tab)

-- Prints the table with only the specified columns. Also prints them in that order
rdb.tab(tab, {"id", "debt"})


-- A generic method thats useful when you don't have a tidy table like the one above
--
-- "debt_table" is a unique id
rdb.tab_init("debt_table", {"Id", "Name", "Debt"})

for _, entry in pairs(tab) do
    rdb.tab_entry("debt_table", {entry.id, entry.name, entry.debt})
end

rdb.tab_end("debt_table")

this prints a table that looks like this:

Id Name                 Debt
1  "Joe"                20000
2  "Little timmy"       45000
3  "Blue collar connor" 0
4  "USA"                40363274597067

rdb.line(from, to, [expire]) 🔗

Draws a line from position from to position to in the world. expire is how long it will last, defaults to 10

rdb.add_active_line(player, target) 🔗

Draws a line originating from player that points towards target position. The line is continiously updates

rdb.remove_active_lines(player) 🔗

Removes lines were added to player via rdb.add_active_line()

rdb.benchmark(name, func) 🔗

Returns a new function that calls func and records how long it took to execute. Each call will print a message saying how long it took to execute, how much time the function took since startup in total, and the average time it took each time

local function func(a)
    local count = 0
    for i = 1, a do
        count = count + 1
    end
    return count
end

-- WRONG
-- `rdb.benchmark` returns a new function. calling `func` calls the old one, without the benchmark hooks
rdb.benchmark("my_func", func)

func(10000)

-- CORRECT
-- `func` is replaced by the new function
func = rdb.benchmark("my_func", func)

func(10000)

rdb.start_benchmark(name) 🔗

Starts a new benchmark identified by name

Note: There is some inherent overhead created by benchmarks. The absolute values can be a bit bigger than they should be (more apparent the less it takes to execute once). but relative to each other it should be fine

rdb.end_benchmark(name) 🔗

Stops a benchmark identified by name. Will print the duration, the average time and total (if repeated)

rdb.benchmark 🔗

Recipe creator 🔗

Right click to open a menu. Put items on the grid to define a recipe. The rightmost slot voids any items put inside

It can get pretty laggy, so make sure to use the search filter

The recipes are written to the terminal as lua code that can be directly copied to your mod

Credit 🔗

As the name suggests, the mod was made by rstcxk (me) and is licensed under the AGPLv3 or later

Parts of LMD's dbg code was adapted, especially in the REPL code

Reviews

Review

Do you recommend this mod?

  • No reviews, yet.

Releases

All releases