Versión en español de esta publicación.
This weekend I’ve been working on some lua scripts with which I was having some problems debugging the flow of the code. I decided to write a small function in order to print some information of the current function flow and parameter values.
The first function presented below receives the current function name as first parameter and a parameter list that is used to create a nice formated flow function string to print. The second function is an example on how to use the first function to print the flow.
local function debug_print_trac(func, ...) local res = func .. "( "; for i,v in ipairs(arg) do res = res .. tostring(v) .. " "; end res = res .. " )"; debug_print(res); end local function set_monitor(monitor) debug_print_trac(debug.getinfo(1, "n").name, monitor); if (monitor == "principal") then set_window_position(0,0); else set_window_position(2561,0); end end
And here are some printed results of function calls. We have our current flow functions and its parameters values printed.
set_top( false ) Window Name: The Linux Programming Interface Application name: Document Viewer max_in( principal 4 false ) set_monitor( principal )
¡Cheers!
-Yohan