Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Edukira joan

Modulu:debug

Wiktionarytik

Documentation for this module may be created at Modulu:debug/dok

local export = {}

-- Convert a value to a string
function export.dump(value, prefix)
    local t = type(value)
    
    prefix = prefix or ""
    
    if t == "string" then
        return '"' .. value .. '"'
    elseif t == "table" then
        local str_table = {}
        
        table.insert(str_table, " {")
        
        for key, val in pairs(value) do
            table.insert(str_table, " " .. prefix .. "\t[" .. export.dump(key, prefix .. "\t") .. "] = " .. mw.ustring.gsub(export.dump(val, prefix .. "\t"), "^ ", "") .. ",")
        end
        
        table.insert(str_table, " " .. prefix .. "}")
        
        return table.concat(str_table, "\n")
    else
        return tostring(value)
    end
end

function export.track(key)
	local frame = mw.getCurrentFrame()
	if key then
		if type(key) == "table" then
			for i, value in pairs(key) do
				pcall(frame.expandTemplate, frame, { title = 'tracking/' .. value })
			end
		else
			pcall(frame.expandTemplate, frame, { title = 'tracking/' .. key })
		end
	else
		error('No tracking key supplied to the function "' .. track .. '".')
	end
end

-- Trigger a script error from a template
function export.error(frame)
    error(frame.args[1] or "(no message specified)")
end

return export