blob: 1e5911e4d64d00cf3454d8f28fe2b080655c8d89 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001* What is LPC?
2
3LPC is the language in which LPmud objects are written.
4LPC stands for Lars Pensj| C. As one might surmise from the name,
5LPC is based on the syntax of C. LPC provides the C while loop, for loop,
6if statement, switch statement, a variant of sscanf, and integer data type,
7(LPC also provides other data types not in C such as the object and the
8mapping). LPC uses C's syntax for defining and calling functions and for
9declaring variables. Note that LPC's version of the string datatype is
10much different from that provided by C. See the LPC tutorial on syntax
11and language constructs for more information.
12
13Here are some differences between LPC and C:
14
15There is no need for a function named "main" in LPC objects (although there
16is one called "create").
17
18The efuns (or system calls) provided by the gamedriver are different than
19those typically found in the C library (libc.a).
20
21There is no malloc(). However, there is an allocate(int value) efun that
22lets space be allocated for arrays. Note that the argument to 'allocate'
23is not in units of bytes, but rather in units of elements.
24
25Memory is never explicitly deallocated. The gamedriver keeps track of
26how many times a given piece of data has been referenced. When the
27reference count goes to zero (when no object has a copy of that variable),
28then the space used by the variable is reclaimed (garbage collected).
29
30The string data type in LPC is closer to that provided by BASIC than that
31provided by C. Strings are not declared as arrays of characters but rather
32as a basic intrinsic type. Strings may be concatenated using the '+' operator.
33
34For example, the LPC statements:
35
36string ack;
37
38ack = foo + bar;
39
40are equivalent to the C statements:
41
42char *ack;
43
44ack = (char *)malloc(strlen(foo) + 1);
45strcpy(ack,foo);
46ack = (char *)realloc(strlen(ack) + strlen(bar) + 1);
47strcat(ack,bar);
48
49Note: ack[i] may not appear as an lvalue (i.e. ack[i] = 'a'; will not
50work as expected).
51
52LPC is an interpreted language (however it is compiled into an internal
53compact tokenized form before being interpreted).
54
55LPC has no structures or unions. In fact, the -> operator is used to
56indicate a call to another object. The mapping datatype can serve
57as an effective substitute for structures in some situations.
58
59sscanf does not work in the same way as in C. arguments to sscanf need not
60be pointers (since LPC does not have the explicit pointer data type). Also,
61sscanf(arg,"%s %s",str1,str2) does not operate as the C programmer would
62expect. In C, the first word of arg would be copied into str1 and the
63second word of arg into str2. In LPC, the first word is copied into str1
64and the _remainder_ of arg is copied into str2.