I then took it a step further and created a "help" UDF which I use in the chat window.
Like this:
[help("help")]
Help for "help": Returns the tooltip text for a macro. Usage [help("macro name")]
[help("openDialog")]
Help for "openDialog": openDialog arguments: Name, Width, Height, Input, Temporary, Title, NoFrame, Content
It searches for macros on its home library token first, then looks at other tokens if it cannot find it. My problem is that most useful things such as UDFs will be stored on a library token, and the getTokens and getTokenNames functions do not return library token IDs. Am I missing something or is there no way to obtain the library tokens identifiers?
Here is the code for those that are interested.
Code: Select all
<!-- return tooltip text for macro -->
[h: tokName="lib:Input"]
[h: switchToken(tokName)]
<!-- create thyself -->
[h, if(!isFunctionDefined("help")):defineFunction("help", "help@"+tokName)]
<!-- bug out if no arguments provided -->
[s, h: assert(if(arg(0)=="",0,1), "Help: No function name provided", 0)]
<!-- get the tooltip text from macro on this token -->
[h: macroName=arg(0)]
[h: macroIndex=getMacroIndexes(macroName)]
<!-- if found do one thing, if not, do the other thing -->
[s, if(isNumber(macroIndex)), code:{
<!-- branch for macro found locally -->
[h: tipText=json.get(getMacroProps(macroIndex, "json"), "tooltip")]
[r, if(tipText==""): "Help for ""+macroName+"": No tip available."; "Help for ""+macroName+"": "+tipText]
};{
<!-- branch for macro external search -->
[h: allTokens=getTokens("json")]
[h: numTokens=json.length(allTokens)]
[h:tok=0][h: helpString=""][h:tipText=""]
<!-- loop through tokens until macro found -->
[h, while(tok < numTokens), code:{
[h: switchToken(json.get(allTokens, tok))]
[h: tok=tok+1]
[h: macroIndex=getMacroIndexes(macroName)]
[h, if(isNumber(macroIndex)): tipText=json.get(getMacroProps(macroIndex, "json"), "tooltip")]
[h, if(tipText=="" && isNumber(macroIndex)): helpString="Help for ""+macroName+"": No tip available."]
[h, if(tipText!="" && isNumber(macroIndex)): helpString="Help for ""+macroName+"": "+tipText]
[h, if(helpString!=""):tok=numTokens]
}]
<!-- spit out the results -->
[r, if(helpString==""): "Help for ""+macroName+"": Macro was not found."; helpString]
}]