Help:Lingua Basics
Lingua is a very basic scripting language that allows you to control how Povo looks, as well as what Povo can do. You can use Lingua to create sophisticated templates, as well as to create mini search engines to help others find local information. This page contains the basics of how to use Lingua to create intelligent templates.
You can embed Lingua into your templates to control the way your templates render. Blocks of Lingua code are delimited by <% and %> symbols. For example, a template might look like:
This is my template. I'm going to print "Hello World" from Lingua.
<% print("Hello World!") %>
In this template,
print("Hello World!") is Lingua code that will be executed and its results placed inside the template as it renders. This is the same as if the template had been:
This is my template. I'm going to print "Hello World" from Lingua.
Hello World!
When a template is rendered, all of the embedded Lingua in the template is executed first, and then any regular wiki variable replacement is done. You can think of Lingua as a preprocessor for templates.
Number literals can be decimal or hexadecimal integers as well as floating point numbers. Examples:
string literals can be delimited by single or double quotes. They may not span lines and do not escape sequences like \n, \t, or \0x2a. Examples:
- "What is the answer to life, the universe, and everything?"
- 'What is the answer to life, the universe, and everything?'
Variables in Lingua are dynamically typed and can be used without being declared. You can create a variable by just setting it equal to a value:
myVariable = 5 // assign the number five to the variable named "myVariable"
print(myVariable)
myVariable = "Some words" /* reassign the variable "myVariable" with the string "Some words" */
print(myVariable)
When you ask for the value of a variable in Lingua, if you have not SET the value directly, Lingua will try to find an argument passed to the template with the same name. Put another way, if you declare a variable in Lingua, it will "hide" the argument that was passed to the template by the same name.
There are five built-in variable types in Lingua:
| Variable Type
| Description
|
| Missing
| The default type for an uninitialized variable. If a variable has no value, its type will be missing, which you can test with "if x is missing print('yo') end"
|
| Boolean
| A true or false variable.
|
| Integer
| A whole number ranging from -2,147,483,648 to 2,147,483,647
|
| Double
| A 64-bit floating number
|
| String
| A series of characters
|
| NotANumber
| An invalid mathematical result. Variables will have the NotANumber type if they are set to the result of an invalid operation, such as dividing by zero
|
| DateTime
| An instant in time. There is a special variable called Now which returns the current time
|
The "if" statement controls program execution based on the result of a boolean expression. Here's a simple example:
myVariable = true
myOtherVariable = false
if myVariable
print("It's true!")
elseif myOtherVariable
print("It's not true, but the other thing is true!")
else
print("Nothing is true!")
end
This will print "It's true!". All if statements must be completed with an "end" statement, and can contain any number of "elseif" statements and one "else" statement.
The foreach statement allows you to iterate over a range of numbers, or over a collection. Here's a simple example:
foreach i in 1..5
print(i)
end
This will print out the numbers 1 through 5. Similarly:
foreach i in 5..1
print(i)
end
This will count down from 5 to 1. You can use variables in your range as well:
start = 1
end = 10
foreach i in start..end
print(i)
end
You can also use foreach to iterate over a collection. When a variable is treated as a collection, it is split up as a comma-delimited list into a set of items. For example:
myList = "eggs,ham,toast"
print("I ate ")
foreach food in myList
print(" " + food)
end
This will print "I ate eggs ham toast".
keywords "continue" and "break" are used to control flow inside of for/foreach statements.
When you call a template in Povo, all of the named parameters passed into the template will be automatically available as variables to Lingua. So, for example, in the following template call:
{{MyTemplate
| MyArg = 5
| MyOtherArg = Povo!
}}
There will be two variables defined when the "MyTemplate" call is executed. If "MyTemplate" was the following:
<%
if MyArg > 0
%>
''{{{MyOtherArg}}}''
<%
end
%>
Then the output of the template would be "
Povo!".
The form:
''{{{MyOtherArg}}}''
is the same as:
''<%=MyOtherArg%>''
and:
''<% print(MyOtherArg) %>''
and:
<%
print("''")
print(MyOtherArg)
print("''")
%>
Unnamed and Unspecified Template Parameters
The associative array
Arguments is always available to templates, containing all parameters passed in the template call.
print("Positional Argument 1: + Arguments["1"])
print("Positional Argument 1: + Arguments["2"])
If you know the names of the arguments you can find them in the array:
print("MyArg: + Arguments["MyArg"])
print("MyOtherArg: + Arguments["MyOtherArg "])
You may also pass the arguments in a sub template call:
{{MySubTemplate|<%=Arguments%>}}
with other parameters:
{{MySubTemplate|NewParam=Yes|<%=Arguments%>}}
or passed from another template:
{{MySubTemplate|SomeParameters={{MyGetAssociativeArray}} }}
| < | ?? | contains | % |
| > | is | does not contain | or |
| <= | exists | contains any | and |
| >= | is not | does not contain any | not |
| == | is a | + | ! |
| = | is not a | - | xor |
| <> | like | / | |
| != | is like | * | |
Lingua has a set of functions. they are invoked by NAME(param1,param2,...).
Thank you for your contribution. You've taken a huge step to making Povo the "word on the street,"
and we appreciate it very much. Because of the complexity of the "wiki text" and code that can be used
on Povo, in order to edit this section in the future you must click the "edit" button to the right of the section
heading (or for the whole page).