Icon representing a recipe

Recipe: LUA Help Searcher -- Brow42

created by brow42

Profile


Name
LUA Help Searcher -- Brow42
ID
46122
Shared with
Public
Parent
None
Children
None
Created on
July 28, 2018 at 05:09 AM UTC
Updated on
July 28, 2018 at 05:09 AM UTC
Description

GUI interface to help(). For short descriptions, names, syntax. Open recipe output window! Blank options matches everything.

Best for


Code


--[[ =================================== * LUA Function Search * Original Author: Brow42 * Version 1.0 May 22, 2013 * Searches Funcion names by case-insensitive substring * Can be limited by namespace. * * Version 1.1 Jan 27, 2013 * added undo namespace * * Version 1.2 Jul 27, 2018 * added filter namespace --]] title = 'LUA Function Search' -- List of all the functions in these known namespaces functions = {} functions['absolutebest'] = absolutebest functions['band'] = band functions['behavior'] = behavior functions['contactmap'] = contactmap functions['creditbest'] = creditbest functions['current'] = current functions['dialog'] = dialog functions['filter'] = filter functions['freeze'] = freeze functions['puzzle']= puzzle functions['recentbest'] = recentbest functions['recipe'] = recipe functions['rotamer'] = rotamer functions['save'] = save functions['scoreboard']= scoreboard functions['selection'] = selection functions['structure'] = structure functions['ui'] = ui functions['undo'] = undo functions['user'] = user functions['<global>'] = { print = print } -- Cant just leave this blank. Also, help() has no help function test() for namespace, functable in pairs(functions) do for funcname, func in pairs(functable) do print (namespace,funcname) help(func) end end end -- Return the keys of the hash table in ascending order function keys(tab) local k = {} for x,_ in pairs(tab) do k[#k+1] = x end table.sort(k) return k end -- Set up multi-page dialogs. Save each dialog settings to options rc = 0 page = 1 k = keys(functions) options = {} for i = 1,#k do options[k[i]] = false end options.search = '' -- A 2 page dialog while rc ~= 1 do -- loop until Okay -- split the keys in half for smaller dialog range = { { 1, math.floor(#k/2)+1 }, {math.floor(#k/2)+2, #k} } more = { 'Next','Previous' } d = dialog.CreateDialog(title) d.search = dialog.AddTextbox('Search',options.search) for i = range[page][1], range[page][2] do d[k[i]] = dialog.AddCheckbox(k[i],options[k[i]]) end d.okay = dialog.AddButton('Search',1) d.cancel = dialog.AddButton('Cancel',0) d.more = dialog.AddButton(more[page],2) rc = dialog.Show(d) if rc == 0 then return end -- Always save results for i = range[page][1], range[page][2] do options[k[i]] = d[k[i]].value end options.search = d.search.value -- Change page if rc == 2 then page = 3 - page end end -- Check if any boxes checked (no boxes == all boxes) all_by_default = true for i = 1, #k do if options[k[i]] then all_by_default = false break end end n = 0 url_format = 'http://foldit.wikia.com/wiki/Foldit_Lua_Function_%s%s' for i = 1,#k do if options[k[i]] == true or all_by_default then -- If we want to look in this namespace f = keys(functions[k[i]]) first_line = true for j = 1,#f do -- do substring search on all functions in namespace if options.search == '' or string.find(f[j]:lower(),options.search:lower()) then if first_line then print('===================') print() first_line = false end help(functions[k[i]][f[j]]) print() n = n + 1 if k[i] ~= '<global>' then ns = k[i]..'.' else ns = '' end url = url_format:format(ns,f[j]) end end end end -- Make a nice dialog reminding people where the output is d = dialog.CreateDialog('Results') if n == 0 then d.label = dialog.AddLabel('No Matches!') elseif n == 1 then d.label = dialog.AddLabel('One result found (check output window).') d.label2 = dialog.AddLabel('Detailed info *may* be at English wiki at:') d.url = dialog.AddTextbox('URL',url) else d.label = dialog.AddLabel(string.format('Multiple results (%d) found (check output window).',n)) end d.okay = dialog.AddButton('Okay',1) dialog.Show(d)

Comments