The debug module exposes information about functions and compiled code, including function metadata, bytecode instructions, upvalues, and source line information. It is intended for tools that inspect Teascript programs.
debug.funcinfo
function
debug
Signature
function debug.funcinfo(proto, pc)Description
The function
funcinfo provides information about a function prototype.Parameters
proto- The function prototype to inspect
pc- An optional bytecode position (default: 0)
Example
import debug
// Inspect a function's prototype
var info = debug.funcinfo(my_function)
print("Function name:", info.name)
print("Defined from line:", info.linedefined)
print("Defined to line:", info.lastlinedefined)
print("Number of parameters:", info.params)
print("Number of optional parameters:", info.optparams)
print("Number of constants:", info.kconsts)
print("Number of upvalues:", info.upvalues)
print("Number of bytecodes:", info.bytecodes)
print("Stack slots:", info.stackslots)
print("Is vararg:", info.isvararg)
print("Has children:", info.children)
// Inspect at a specific bytecode position
var info = debug.funcinfo(my_function, 5)
print("Current line at pc 5:", info.currentline)debug.funck
function
debug
Signature
function debug.funck(proto, index)Description
The function
funck retrieves a constant from a function prototype’s constant table.Parameters
proto- The function prototype to inspect
index- The index of the constant to retrieve
Example
import debug
// Get the first constant
var constant = debug.funck(my_function, 0)
print("Constant at index 0:", constant)
// Get a string constant
var name = debug.funck(my_function, 1)
print("Constant at index 1:", name)
// Iterate through all constants
var info = debug.funcinfo(my_function)
for const i in 0..info.kconsts
{
var k = debug.funck(my_function, i)
print("Constant " + i + ": " + tostring(k))
}debug.funcbc
function
debug
Signature
function debug.funcbc(proto, index)Description
The function
funcbc retrieves a bytecode instruction from a function prototype.Parameters
proto- The function prototype to inspect
index- The index of the bytecode instruction to retrieve
Example
import debug
// Get the first bytecode instruction
var bc = debug.funcbc(my_function, 0)
print("First bytecode:", bc)
// Inspect all bytecode instructions
var info = debug.funcinfo(my_function)
for const i in 0..info.bytecodes
{
var bc = debug.funcbc(my_function, i)
print("Bytecode " + i + ": " + bc)
}debug.funcuv
function
debug
Signature
function debug.funcuv(proto, index)Description
The function
funcuv retrieves information about an upvalue from a function prototype.Parameters
proto- The function prototype to inspect
index- The index of the upvalue to retrieve
Example
import debug
// Get the first upvalue
var uv = debug.funcuv(my_function, 0)
print("Upvalue at index 0:", uv)
// Inspect all upvalues
var info = debug.funcinfo(my_function)
for const i in 0..info.upvalues
{
var uv = debug.funcuv(my_function, i)
print("Upvalue " + i + ": " + uv)
}debug.funcline
function
debug
Signature
function debug.funcline(proto, offset)Description
The function
funcline provides the source line number corresponding to a bytecode offset in a function prototype.Parameters
proto- The function prototype to inspect
offset- The bytecode offset
Example
import debug
// Get the line number for a specific bytecode offset
var line = debug.funcline(my_function, 0)
print("Line at offset 0:", line)
// Map bytecode offsets to source lines
var info = debug.funcinfo(my_function)
for const i in 0..info.bytecodes
{
var line = debug.funcline(my_function, i)
print("Bytecode " + i + " is at line " + line)
}