LDMud logo: an emblem with three snakes, on the left behind that emblem a cogwheel. In front of both is a sword.

LDMud

Home of LDMud

View the Project on GitHub ldmud/ldmud

A Quick Tour of LPC - Introduction

LPC is an object oriented language based on C. A simple program would look like:

    void create()
{
write("Hello, World!");
}

In the above example you see a function called create(). This function has no return value (void) and is usually called on instantiation of the program, just like main() in an ordinary C program.

In this function a driver function write, a so-called efun, is called with a string as an argument. write just prints the text to the current user. This is where you'll initialize your object (set up all variables, load other needed objects, etc.).

In an LPMud there are no long-running functions. Each LPC functions needs to return almost immediately. There is no sleep function or mechanisms to wait for something. That's because the virtual machine is single-threaded. While one LPC function is running, nothing else will be executed. And if you manage to have an endless loop, the whole VM hangs. To prevent such a situation there is an evaluation counter: Each VM instruction that is executed upon an external event (like some player entering a command) is counted and if that count exceeds a given limit an error is thrown and the execution usually ends.

To react on external events you'll have to implement that as a function and register that function for the desired event (eg. with add_action for a command entered by a player, or call_out for a countdown). Some functions don't need to be registered and only need to have just the right name, like create() for object creation, or init() for some player entering into the vicinity of the object. But we'll have more of that later.

This documentation is just a quick introduction into the core LPC language. A more complete documentation you'll find in the LDMud source. Also to implement a MUD you'll need an additional library poviding items, rooms, non-player and player handling, grammar, etc., the so-called mudlib. There are several different mudlibs out there, their discussion is not part if this introduction.