LPC is a dynamically typed language, but has some also some elements
of static typing. That means at runtime each value has some specific
type and you cannot determine from the source code what type that
will be. But it is possible to specify types in the LPC source code
and thus prevent some type errors on compile-time. But this is
voluntary, you can always use the type mixed which
means that it can take any type.
Value Types
There are two kind of types: value and reference types.
Value types are copied with each assignment. When you change
a variable containing a value type only that instance is modified.
On the other hand for a reference type value an instance is
created in memory, and all variables it gets assigned to
just get a reference to that one instance.
When you change that value it's modified in all
variables that contain a reference to that.
LPC offers the following value types:
int
A signed integral number ranging from __INT_MIN__ to __INT_MAX__,
on 32 bit platforms it's 32 bit wide, and on 64 bit platforms it's 64 bit wide.
float
A floating point number ranging from __FLOAT_MIN__ to __FLOAT_MAX__.
string
A text (a sequence of characters). LPC strings are mutable and have variable length.
bytes
Sequences of bytes (8 bit values). Similar to strings LPC bytes are mutable and have variable length.
symbol
Symbols are identifier names. There are used for variable names
in lambda closures.
lpctype
Variables of type lpctype can store an LPC type,
that can be used to check against other values or types.
Reference Types
Arrays
An array is a list of values. Arrays are reference types: When you modify an element inside
an array all variables holding a reference to that array see that change.
But as an exception every operation that changes the length of the array creates a
new array instance leaving the original instance alone. So only the variable
this size changing operation was carried out with references the new array.
Arrays are specified with the type of the member elements followed by a star.
Members can be accessed using the [] operator.
Arrays are zero-based, so the first element has index 0.
mapping
A mapping, also known as associative array, dictionary or hash table,
maps a key to one or more values. In LPC there are also
mappings without a value implementing a set.
Similar to arrays values are accessed using the [] operator:
struct
Structs group a collection of values together.
Each struct must be defined first:
Usage:
object
As LPC is an object-oriented language, objects are the main ingredient.
An object variable contains the reference to one.
lwobject
A lightweight object is a middle ground between structs and full-blown objects.
They are very similar to objects but have automatic lifetime.
closure
Closures reference executable code, usually other functions in
an object, but may also reference efuns (driver functions)
or code that was compiled at run-time (lambda functions).
Closures are usually not mutable. They are executed with funcall:
coroutine
A coroutine variable holds the execution state of an asynchronous function.
Such a function can be suspended and continued at a later time.
As a specialty of LPC each variable can always contain the value 0 regardles of its specified type.
That is also the initial value of each variable and the one value that is considered 'false' in
conditional expressions.