Home of LDMud
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.
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
__INT_MIN__
to __INT_MAX__
,
on 32 bit platforms it's 32 bit wide, and on 64 bit platforms it's 64 bit wide.
int i = 10;
float
__FLOAT_MIN__
to __FLOAT_MAX__
.
float f = 10.42;
string
string str = "Hello!";
bytes
bytes buf = b"Hello!";
symbol
symbol s = 'var;
int* numbers = ({1, 2, 4, 8});
[]
operator.
Arrays are zero-based, so the first element has index 0.
numbers[3] = 9;
mapping
mapping m = ([ "key1": 10, "key2": 20 ]);
mapping set = ([ "abc", "def", "xyz" ]);
[]
operator:
m["key3"] = 30;
struct
struct Foo
{
int member1, member2;
string text;
};
struct Foo var = (<Foo> 10, 20, "text");
var->member2 = 42;
object
object ob = this_player();
ob->query_name();
lwobject
lwobject lwo = new_lwobject("/obj/foo");
lwo->set_bar(42);
closure
closure cl = #'write;
funcall(cl, "Hello, World!");
coroutine
async void fun()
{
// Do something.
yield(); // Pause
// Do something later.
}
coroutine cr = fun();
call_coroutine(cr);
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.