LPC Manual

LPC Manual for DarkRifts coders

Will Guaraldi

This manual covers LPC, the language used for coding mudlib and world content in LPMud and derivative mud drivers.

DarkRifts uses MudOS v22.2b14 and thus this manual caters specifically to that dialect of LPC with some content relating specifically to our mudlib.

This manual is a work in progress and is by no means error-free, comprehensive, or completed. We work on it from time to time fleshing out things that we think our coders are having problems with.

Copyright (c) 2005-2007 DarkRifts.org. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being no Invariant Sections, with the Front-Cover Texts being no Front-Cover Texts, and with the Back-Cover Texts being no Back-Cover Texts. A copy of the license is included in the appendix entitled "GNU Free Documentation License".


Table of Contents
1. Overview of LPC Programming
1.1. Your first LPC code block
1.2. Architecture
1.3. Objects
2. Variables
2.1. Variable Names in LPC
2.2. Variable Types in LPC
2.3. Variable Values in LPC
3. Strings
4. Arrays
4.1. Initializing Arrays
4.2. Testing Arrays
4.3. Adding and Removing Elements in Arrays
4.4. Accessing Elements in Arrays
4.5. sizeof
4.6. Iterating Over Arrays
4.7. Getting a Random Item From an Array
4.8. Arrays of Arrays
4.9. Common Errors
4.9.1. Illegal index
4.9.2. Indexing on illegal type
5. Mappings
5.1. Initializing Mappings
5.2. Testing With Mappings
5.3. Adding and Removing key/value Pairs from a Mapping
5.4. Accessing Elements in Mappings
5.5. Keys and Values
5.6. Size of a Mapping
5.7. Complex Mappings
5.8. Iterating Over Sorted Mappings
5.9. Common Errors
5.9.1. Indexing on illegal type
6. Ints, Floats, and Math
6.1. Types of Numbers in LPC
6.2. Converting Between Number Types
6.3. Operations on Numbers in LPC
6.3.1. Addition in LPC
6.3.2. Subtraction in LPC
6.3.3. Multiplication in LPC
6.3.4. Division in LPC
6.3.5. Modulus in LPC
6.3.6. Parentheses in LPC
6.4. Math Functions in LPC
7. Practices
7.1. About This Chapter
7.2. Variable naming
7.3. Commenting your code
7.4. Properties vs. functions
7.4.1. Reliable masking
7.4.2. Easier implmentation changes
7.4.3. No uncertainty about what to call
7.4.4. Data consistency (timing issues/order of initialization)
7.4.5. When it's good to use properties
8. Debugging
8.1. About This Chapter
8.2. About Debugging
8.3. Methods of Debugging
8.4. Log Files, Bug Reports, and Collecting Data
A. GNU Free Documentation License
List of Tables
6-1. Math-related functions
List of Examples
1-1. Sample LPC code: nectar.c
4-1. Initializing arrays
4-2. Initializing arrays with allocate()
4-3. Testing a variable of type array to see if it is defined
4-4. Testing a variable of type array to see if it is defined
4-5. Adding elements to an array
4-6. Deleting elements from an array
4-7. Accessing elements in an array
4-8. Using the range operator on arrays
4-9. Using sizeof() on an array
4-10. Iterating over arrays
4-11. Getting a random item from an array
5-1. Initializing mappings
5-2. Declaring mappings
5-3. Initializing an empty mapping
5-4. Initializing a non-empty mapping
5-5. Testing a variable of type mapping to see if it is defined
5-6. Testing a variable of type mapping to see if it is defined
5-7. Adding a key/value pair to a mapping
5-8. Adding a key/value pair to a mapping using +=
5-9. Deleting a key/value pair from a mapping
5-10. Referencing a key/value pair in a mapping
5-11. Calling keys() on a mapping
5-12. Calling values() on a mapping
5-13. Using foreach on a mapping
5-14. Using sizeof() on a mapping
5-15. Mapping of mappings