Moving this discussion to a new thread to save derailing waterwingz' script compression thread further (
http://chdk.setepontos.com/index.php?topic=12117)
Attached is a patch against 1.3 revision 3788 with some changes to script parameter handling.
This is a work in progress, so may have issues.
Changes:- Script parameter values no longer stored in 'conf' structure, or saved to CHDK config file.
- Replaced static arrays to store parameter info with dynamically allocated structures. Saves memory as most scripts have only a few parameters.
- Script file only parsed once for parameter details. Parameter values can be reset without parsing script again.
- No hard wired limit on number of parameters.
- Variable names for Lua can be up to 64 characters long (but must start with a letter).
- 'A' - 'Z' allowed for uBasic variables (not fully tested).
- Shorthand syntax for parameter definition in script files (see below). The vidtest.lua script has been updated to demo this.
- Boolean data type for parameter variable - Lua only (see below).
- New name and format for saved script parameter files (see below).
Shorthand parameter syntax:In addition to the existing syntax for defining script parameters, this patch adds a new shorter syntax.
Parameters can be defined as
#name=value "title" - for simple numeric parameters
or #name=value "title" [min max] - specify range for parameter (@range)
or #name=value "title" {opt1 opt2 ... optN} - specify list of options for user to select from (@values)
The '=' between 'name' and 'value' is optional (if not present use a space), spaces can be inserted before and after if desired.
Single or double quotes can be used for 'title' but should match (quoting is mandatory).
Boolean Lua variable:Currently defining the [min max] range as [0 1] creates a checkbox for the user; but creates the variable in Lua as a number (with a value of 0 or 1).
In this patch defining the range as [1 0] also give the user a checkbox; but now creates the variable as a boolean in Lua.
This syntax will probably change as it is not very intuitive - proof-of-concept for now.
Saved parameter values:In the current system the parameter values are saved to files named scriptname_N, where 'scriptname' is the file name of the script and N is an integer from 0 to 9. The data is saved with the old @param and @default definition syntax.
This version saves to scriptname.N using '#name=value' for the syntax. The filename change allows testing without overwriting existing saved parameters. The old files will still be read if there are no new files.
Known Issues:- There is no error checking when parsing the script parameters (the current system does not have any either). This should probably be fixed.
- 1 character uBasic variable names is not enforced. "@param v1 var1" and "@param v2 var2" will both be accepted; but map to the same variable.
Phil.