ldoc
ldoc copied to clipboard
Formatting Custom Display Name Handler
trafficstars
This is part of my config.ld:
new_type('chatcmd', 'Chat Commands', false, 'chatparam')
custom_tags = {
{'chatparam', title='Parameters',},
}
local function chatcmd_handler(item)
local output = item.name
for i, p in ipairs(item.tags.chatparam) do
output = output .. ' [' .. p .. ']'
end
return output
end
function custom_display_name_handler(item, default_handler)
if item.type == 'chatcmd' then
return chatcmd_handler(item)
end
return default_handler(item)
end
My problem is in the chatcmd_handler function. For each item.tags.chatparam, I want to take only the first word & append it to the output, not the entire string. Similar to the way functions are displayed. But I am not sure how to split the string or extract a substring. I don't seem to be able to use standard Lua libraries from within the config.ld. I am not very experienced with Lua, but I have dabbled in it for a few months, including interactive interpreters.