[DGD]Re Need tips with LPC function Im writing.

sampsa at netsonic.fi sampsa at netsonic.fi
Tue Mar 23 19:10:28 CET 1999



On Wed, 24 Mar 1999, MUD Account wrote:

> > Umm, we actually have strstr() and strchr() kfuns. We also have
> >new_string(int lenght, int fillchar) and break_string() kfuns with color
> >support, because I use these a lot.
> 
> Hmm these arent part of standard DGD surely?  I take it you mean
> actually kfuns?

 Yes, I am using my own extra set of extra kfuns of choice. LPC simulation
is not actually the fastest way to handle low level stuff, and I consider
myself experienced enought to optimize mudlib by moving the most commonly
used functions to C code. One could also use "precompiled" code, but still
using C library functions is more efficient. But I must warn you if you
choose the same path, I've once fallen to optimize a mudlib too much, and
lost some flexibility of the mudlib structure and it became very hard to
extend. So as far as you're in development phase and MUD is not running,
keep on working to get it up and running, and optimize later!

> > Can you tell me where to find this, I would like to take a look on it?
> 
> Its in the package by Frank Schmidt, called MudOS4DGD.
> Or MudOSa4DGD.  Got some useful functions - especially
> in the string efuns.  And its got the sprintf() package.
> Currently writing my own cut version.
> 
> > As does explode(find+str+find,find), extra separator to both ends of
> >string to nullify effect of stripping in kfun? This is also done in 2.4.5
> >simulation library.
> > implode(explode(find+str+find,find),find) == str  ->  always true
> > What's your point?
> Dont know what his point was, but I thank you both for your response on 
> this.
> Your help has been of tremendous use.  My function now works,
> although when I used it in my ansi colour daemon, it would cause an
> "Out of ticks" error, when I went to use more to view a long file
> that involved comments.  Reason being that comments of course use
> "*/" and "/*", and I was using (but am not now) "*" as the hmm tag (for 
> want of a better word) character for my ansi colours ie."*bold**red*Hi 
> there*reset*".
> Which in hindsight was kind of stupid.  Anyway, Im wondering if anyone can
> tell me exactly what that error means, and how I can avoid it (besides 
> becoming a better LPC coder :P).  Im willing to post any functions to be 
> pulled apart, as I think I need some tips on LPC, and as Im the only 
> coder working on this project, I dont have anyone I can get tips off of 
> :)  Im thinking my background in C is possibly hurting the speed of any 
> functions Im writing. Anyway, thanks for your time, and thanks for your 
> responses. Take care,

Out of ticks means that executing the LPC code takes more resources you've
granted to it. This might also be an indication of endless loop. Ticks are
kind of safety matter. Currently available ticks can be queried via
status() kfun.

BTW. Color search & replace can also be done by parse_string()

You might want to check out and extend the piece of code I've included.
It's purpose is to setup a grammar to break a string and replace
color codes by the sequences (tune the get_colors to return sequences,
switch is fastest way to do this inside it). parse_colors() returns an
array where the string is split by '*' or *color-code*, the color codes
are replaced in get_colors function. By imploding the returned array to a
string with "" delimiter you get a colored string. 

example:
--
compile color.c
code return $1->parse_string("zyx**yellow* \n  *   *green*");
$1 = ({ "zyx","*","COLOR-*yellow*"," \n  ","*","   ","COLOR-*green*" })
--

To optimize your color code further, you might want to use some less often
separator for marking colors, maybe @^ or something like that.

If you wish, it's also easy to split the lines by \n in the same
grammar.

Notice that the grammar is compiled on first time the code is called, only
one grammar can be simultanously compiled on one object. So if you start
using parse_string, you should have one parse_string grammar per object to
keep it fast.

--- cuticuti, code here ---
 
string *get_color(string *s)
{
    switch(s[0]) {
    case "*yellow*":
    case "*red*":
    case "*black*":
    case "*green*":
    case "*blue*":
    case "*magenta*":
    case "*cyan*":
    case "*gray*":
    case "*orange*":
	return ({ "COLOR-"+s[0] });
	break;
    default:
	error("This code should not be reached");
	break;
    }
}

string *parse_colors(string input)
{
    return parse_string("\
anystr = /[^*]+/ \
"+"\
prod: sub_color               \
prod: anystr                  \
prod: '*'                     \
prod: prod prod               \
"+"\
color: '*yellow*'   \
color: '*red*'      \
color: '*black*'    \
color: '*green*'    \
color: '*blue*'     \
color: '*magenta*'  \
color: '*cyan*'     \
color: '*gray*'     \
color: '*orange*'   \
"+"\
sub_color: color ? get_color \
",input,0);
}

--- cuticuti ---

 - Sampsa Ranta
   smapsa at netsonic.fi


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list