Icon representing a recipe

Recipe: LuaHelp2Help 1.0

created by LociOiling

Profile


Name
LuaHelp2Help 1.0
ID
101069
Shared with
Public
Parent
None
Children
Created on
June 04, 2015 at 19:56 PM UTC
Updated on
June 04, 2015 at 19:56 PM UTC
Description

Not a foldit recipe. LuaHelp2Help is a standalone Lua script, used as a step in producing the "Foldit Lua Functions" page on the wiki. This script takes the output of the "help()" command in foldit as its input.

Best for


Code


--[[ LuaHelp2Help This script generates a foldit recipe consisting of a list of help commands. The input to this script is the output of the foldit help command, which is a list of function signatures. The list of functions is generated by running the command: help () in the Foldit client. The result is a list of function signatures: void print([arg1,...,argN]) boolean absolutebest.AreConditionsMet() number absolutebest.GetEnergyScore() ... LuaHelp2Help converts the function signatures into another Foldit script, a series of commands in the form: help ( functionname ) The output from LuaHelp2Help run as a foldit recipe. The output from this recipe can then be run through the next program, LuaFunctions, to generate the "Foldit Lua Functions" page markup. This is a command line LUA program. The command line syntax is: lua LuaHelp2Help.lua helpfile helpfile is the output of the foldit "help()" command The output is written the the "standard output" (stdout) The help() output may contain errors, such as the line void structure.TweakRotateinteger segmentIndex, number angle) found in the current foldit release, which is missing the opening "(" on its parameter list. LuaHelp2Help issues an error message for errors of this type. Consider correcting the error by adding the missing parenthesis. revision history ---------------- 2015/06/04 -- LociOiling -- new function ]]-- function main () local Recipe = "Lua Help2Help" local Version = "1.0" local ReVersion = Recipe .. " v" .. Version print ( "-- " .. ReVersion ) -- -- I'd like to have an argument, please -- if arg == nil then print ( "LuaFunctions is a standalone Lua program " ) print ( "(not a foldit recipe)" ) return end if #arg < 1 then print ( "-- " .. "usage: LuaHelp2Help helpfile" ) print ( "-- " .. "helpfile - output of the foldit \"help()\" command" ) return end -- -- variables used in scanning the input file -- local ll = 0 -- line count local start local stop local tag local rettype local funcname local rest local DEBUG = false local funcout = 0 local badfunc = 0 local tagcnt = 0 -- -- scan input file created by a series of calls to foldit "help" function, each with one function namespace -- for line in io.lines ( arg [ 1 ] ) do ll = ll + 1 if DEBUG then print ( "line " .. ll .. " = \"" .. line .. "\"" ) end -- -- ignore simple XML tags in foldit scriptlog format -- start, stop, tag, rest = line:find ( "(%<*%>)" ) -- not 100% but close enough if tag ~= nil then if DEBUG then print ( "XML tag = " .. line ) end tagcnt = tagcnt + 1 else -- -- peel off the return values -- start, stop, rettype, rest = line:find ( "(%l*)% (.*)" ) if DEBUG then print ( "return type = " .. rettype .. ", rest = \"" .. rest .. "\"" ) end -- -- get the function name, including the name space if present -- start, stop, funcname, rest = rest:find ( "(.*)%((.*)%)" ) if rest == nil then rest = "" end if DEBUG then print ( "function name = " .. funcname .. ", rest = \"" .. rest .. "\"" ) end if funcname ~= nil then print ( "help ( " .. funcname .. " )" ) else print ( "--" .. " invalid line " .. ll .. " " .. line ) badfunc = badfunc + 1 end funcout = funcout + 1 end end print ( "-- " .. ReVersion .. " complete" ) print ( "-- " .. funcout .." functions" ) print ( "-- " .. tagcnt .. " XML tags ignored" ) print ( "-- " .. badfunc .. " invalid lines" ) end main ()

Comments


LociOiling Lv 1

LuaHelp2Help is not a Foldit recipe. It should produce a polite message stating this fact if you run it from your cookbook.

This a standalone Lua script, so you must have Lua installed separately from Foldit to run.

This script takes the output of the Foldit "help()" command and transforms it into a series of "help" commands, one per Lua function. In other words, LuaHelp2Help produces something you can run as Foldit recipe.

When you run the output from LuaHelp2Help in Foldit, the resulting output can be fed into the next stage, LuaFunctions, which is another standalone Lua script.

Due to problems with the "help", some manual fixes are needed to get the desired results.

See http://foldit.wikia.com/wiki/Foldit_Lua_Functions_List_Generation for more details.