Author Topic: Adding new MudOS efun packages  (Read 3019 times)

Offline Hilapdatus

  • Acquaintance
  • *
  • Posts: 13
    • View Profile
    • Dreamverse Support Site
Adding new MudOS efun packages
« on: June 11, 2007, 11:22:12 AM »
Greetings all, I would like to code a few efun packages for MudOS.  I remember seeing a doc somewhere that held a little information about this process -- nothing in depth but still helpful.  Hrm, perhaps it was included with the LIMA 1.0b5 distribution.... I'll have to check.

Do you know of any other references or attempts at documenting efun coding techniques?

I'm a wee bit lazy and don't want to delve in the code blind if I don't need to.  I'd like to get SOME sort of idea of what's going on beforehand.

On a seperate but simliar topic, have other folks coded their own efuns?  Would you mind describing your efforts and be willing to share?

My immediate goal is to create a single efun to generate UUIDs.  I don't want to do this in LPC nor do I want to execute a database query.  My efun is super simple.  It takes no arguments and returns a string.  The C source code, sans-MudOS, occupies five lines of code and uses a library provided by OSSP.  I'll have this efun done in no time but I still won't have an understanding of how efuns operate.

Offline urizen

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Re: Adding new MudOS efun packages
« Reply #1 on: June 22, 2007, 10:36:02 AM »
I've done a little futzing around with packages, mostly to get the mysql functions in the db package working, but they seem pretty straight forward.  Assuming you're package is named 'foo', it requires two files:

packages/foo_spec.c
packages/foo.c

The spec file just contains the LPC prototypes for all the efuns in the package.  In your case, something like:

Code: [Select]
string gen_uuid(void);
The other file contains the actual source for your efuns.  For something simple like this, it would look something like:

Code: [Select]
#include <string.h>
// any other required headers

#include "../lpc_incl.h"
#include "../efun_protos.h"

#ifdef F_GEN_UUID
void f_gen_uuid(void) {
  char *buf;
  // code to malloc buf and store the generated UUID in buf
  push_malloced_string(buf);
}
#endif

Note that the function always returns void, regardless of return value.  The return value is pushed onto a stack using the relevant push_* functions (push_number, push_real, push_object, &c) defined in interpret.c.  Similarly, arguments are not passed in the normal C manner, but are instead accessed through the sp stack pointer.  packages/math.c is a good place to look for simple examples.

Finally, make sure to include:

Code: [Select]
#define PACKAGE_FOO

in local_options before building.

Thanks goes to my company for this incredibly boring teleconference I'm currently listening to for encouraging me to figure out efun implementation through boredom :)