Line 93: | Line 93: | ||
All uBASIC script commands are also available in LUA, almost with the same syntax. |
All uBASIC script commands are also available in LUA, almost with the same syntax. |
||
− | See the [[uBASIC/TutorialScratchpad|Scripting Tutorial]] for a more complete explanation and |
+ | See the [[uBASIC/TutorialScratchpad|Scripting Tutorial]] for a more complete explanation and for the usage of all commands. |
− | If execution/parse error occurs message with line number is shown in mini console. |
+ | If an execution/parse error occurs a message with a short explanation and the line number is shown in the mini console. |
Revision as of 11:56, 17 August 2008
Camera scripting using LUA
Some new CHDK builds includes LUA as additional scripting language, this page is intended to give a overview of the syntax of LUA usage in CHDK scripts.
This is work in process...
LUA Syntax short manual
- Lua is a case-sensitive language
- Lua is dynamically typed, variables in LUA do not have types, there are no type definitions for variables in LUA.
Keywords:
and break do else elseif end false for function if in local nil not or repeat return then true until while
Special CHDK keywords:
click press release shoot sleep require
Variables:
- Lower latin letter from a to z
- Upper latin letter from A to Z
- 32 bit signed integer
- Variables have to start with a character or an underscore
Strings
- Strings are bordered by quotation marks " " (only single lines) or square brackets [[ ]] .
- Strings can be concatenated by two dots ..
Tables
- ToDo
Libraries
Libraries are standard LUA scripts placed either in CHDK\SCRIPTS or CHDK\LUALIB, called within a script with
require "libname"
where libname is the filename of the library file without '.lua' suffix.
This means one can create a library of functions and recycle this lib in scripts with a call to require "libname".
Library files were first searched from CHDK/SCRIPTS, and then if not found, from CHDK/LUALIB; if a file with the required name is available in both folders, the one from the first folder (CHDK\SCRIPTS) is used.
Comments:
Comments starts with a double hyphen -- anywhere outside a string.
If the text immediately after -- is not an opening square bracket [ , the comment is a short comment, which runs until the end of the line. Otherwise, it is a long comment, which runs until the corresponding closing square bracket ] . Long comments are frequently used to disable code temporarily.
Sample:
print("Hello CHDK !") -- this is a line with a comment at the end
The script header:
The header of a LUA script is the same as on a uBASIC script, packed into a long comment - the script parser interpretes this the same way in LUA as in uBASIC.
A Sample LUA header:
--[[
rem 20080815 test script by xxx
@title test script
@param a Duration (min)/-1 disable
@default a -1
@param b Duration (sec)/n of seqs
@default b 5
@param h Endless?
@default h 0
--]]
Script Commands
All uBASIC script commands are also available in LUA, almost with the same syntax.
See the Scripting Tutorial for a more complete explanation and for the usage of all commands.
If an execution/parse error occurs a message with a short explanation and the line number is shown in the mini console.