Language overview
The online documentation for Lua can be found here:
http://www.lua.org/manual/5.1/
Lua is a dynamically typed language. No type definitions are needed for variables in the language; each value carries its own type. Eight default types are used in Lua: nil, Boolean, number, string, userdata, function, thread, and table
Global context and objects:
In Lua, all variables are global variables by default. To create local variables, define the variable with the
local statement:
i = 10 <-- global variable
local i = 1 <-- local variable
Lua Examples
Todo here
client.alert(type(a)) -> nil # as ‘a’ has not been initialized.
a = 1
client.alert(type(a)) -> number
client.alert(type(a)) -> Boolean
Pease note: In DragonRAD application, if variable's value is getting from a Boolean Column, it's value might be displayed as "true" or "false" but it's type is actually a string type.
For Example:
a = aRow.getColumnValue("aTable.BooleanColumn") <-- here the BooleanColumn value is true
client.alert(a) -> Display as "true"
client.alert(type(a)) -> string
a= “a string”
client.alert(type(a)) -> string
a = type <- this is assigning a function to a variable.
client.alert(type(a)) -> function
a = {}
client.alert(type(a)) -> table or array
k = “x”
a[k] = 10 or a[“x”] = 10
client.alert(a[“x”)]) -> 10
a[“x”] == a.x
client.alert(a.x) -> 10
#a means the item for array a{}
Basic Lua Expressions
Arithmetic Operators:
+, -, *, /, ^, %, - (negation)
Relational Operators:
<, >, <=, >=,
=, ~
Logical Operators:
and, or, not
Example 1) when flag is not set, set flag to Aflag value; otherwise, set flag to itself.
Example 2) select the maximum number from a and b
String Concatenation Operator:
Example:
See the string library for additional string functions.
Escape Operator: “\”
Statements:
If Statements:
For Statements:
Function Example: (Note: the function has to be defined before it can be used)
Please
Log In to add a comment