4 Angel Ortega <angel@triptico.com>
9 MPSL (Minimum Profit Scripting Language) is a programming language
10 concieved as an scripting engine for the Minimum Profit Text Editor,
11 though it can also be used as a general-purpose programming tool. An MPSL
12 program consists of a sequence of statements which run from top to bottom.
13 Loops, subroutines and other control structures allow you to jump around
14 within the code. It is a free-form language, meaning that you can format
15 and indent it however you like, as whitespace serves to separate tokens.
17 MPSL borrows syntax and concepts from many languages: C, Perl, Java or
18 JavaScript. Statements end in a semi-colon, blocks are enclosed between {
19 and } (curly brackets).
24 Text enclosed between /* and */ is ignored, as in C. It can span multiple
30 Strings are enclosed around single or double quotes:
32 print("This a string");
33 print('This is also a string');
35 However, double quotes give special treatment to backslash-escaped
36 characters, also as in C:
38 print("Hello, world\n"); /* ends with a new line */
39 print('Hello, World\n'); /* prints Hello, World\n literally */
41 Strings can be broken between lines by using backslashes:
46 Non-ASCII characters (Unicode) can be included in strings using the
49 print("Hello, world \x{263A}\n"); /* a smiley follows the greeting */
54 Function and subroutine calls must enclose its arguments between
55 parentheses, and separate them by commas:
57 print("This is ", 'a list ', "of ", 5, " arguments\n");
59 Parentheses are needed even if a function has no arguments.
64 The number 0, the strings '0' and '' and NULL are all false as boolean
65 values. Any other value is considered true.
67 Variables and data types
68 ------------------------
70 Data types in MPSL match the mpdm (Minimum Profit Data Manager) single,
71 array and hash values. They are very similar to Perl ones. However,
72 variable names don't have a prefix indicating its type as in Perl; they
75 Variables need not be declared (unless for local values, see below); they
76 are created on assignation.
81 A scalar represents a single value. They can be strings, integers or
82 floating point numbers, and they will be converted as required.
88 There are other types of scalar values, as file descriptors and executable
89 values; they will be treated later.
91 Scalar assignation is always by value; by doing
93 a = 100; b = a; b = 5;
95 The a variable still holds its original value of 100.
100 An array represents a list of values. Arrays are zero-indexed. Each
101 element of an array can be of any type (scalar, array, or hash). Array
102 size is dynamic and can grow or shrink at the programmer's wish.
104 workdays = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday' ];
106 print(workdays[0], "\n"); /* prints monday */
108 heterogeneous_array = [ 1, "string", [ 1, 2, 3 ], NULL, function(), workdays ];
110 Array assignation is always by reference; by doing
112 a = [ 10, 20, 30 ]; b = a; b[0] = 100;
114 The value for the element a[0] is also 100; a and b both point to the same
115 array. A special-purpose function, clone(), can be used if you want them
116 to be different values.
118 Arrays grow when assigned to an out-of-bounds subscript:
120 ary = [ 0, 1, 2, 3 ];
121 print("size: ", size(ary), "\n"); /* prints size: 4 */
123 print("size: ", size(ary), "\n"); /* prints size: 101 */
125 The range operator can be used to populate an array with consecutive,
126 integer values, as in the example:
128 ary = [ 1 .. 100 ]; /* ary contains 100 elements, from 1 to 100 */
133 A hash, or associative array, represents a set of key/value pairs. Keys and
134 values can be of any type (scalar, array or hash). However, keys are
135 usually scalar values, in particular strings.
139 'tuesday' => 'martes',
140 'wednesday' => 'miercoles',
141 'thursday' => 'jueves',
142 'friday' => 'viernes'
145 print(en2es_workdays['monday'], "\n"); /* prints lunes */
148 'workdays' => workdays,
149 'weekend' => [ 'saturday', 'sunday' ]
152 Hash definitions *must* use the => to mark key/value pairs.
154 Hash assignation is always by reference, as in arrays (in fact, hashes are
155 just a special case of array).
157 Compact access to hash members
158 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160 Hashes can, and ofter are, used as records. Given the following hash of
165 app['config']['save_on_exit'] = 1;
167 The save_on_exit component can also be accessed by using:
169 app.config.save_on_exit = 1;
171 Please note that variables are *not* automatically created unless the path
172 to them already exist; so 'app' and 'app.config' must exist and be hashes,
173 or the 'save_on_exit' component will not be created and fail silently.
174 This is a common pitfall.
179 A variable name must start with a letter or underscore and can be followed
180 by any number of letters, numbers and underscores. Case is significative,
181 so aaa and AAA and aAa are different symbols.
186 By default, non-existent assigned variables are created as global symbols.
187 Though they are useful, it's not a good programming practice to have all
188 variables as global, so local variables can be used. They are defined by
189 using the local directive:
191 local a; /* creates the local variable a, with NULL value */
192 local b = 100; /* creates the local variable b, with a value of 100 */
194 Local variables have its life limited to the subroutine where they are
195 defined or, if defined inside a block, limited to that block. Inner
196 variables obscure more global ones, as in the example:
198 var = 6; /* global variable var, with a value of 6 */
200 { /* start of block */
201 local var = 10; /* local variable var */
202 print("var: ", var, "\n"); /* prints var: 10 */
203 var = 20; /* local var now has 20 */
204 print("var: ", var, "\n"); /* prints var: 20 */
207 print("var: ", var, "\n"); /* prints var: 6 */
209 Subroutine arguments are treated as local variables.
211 Conditional and looping constructs
212 ----------------------------------
217 MPSL has the usual 'if' conditional construct. The condition can be any
218 MPSL expression, and the conditional code must be written between braces
219 if it's more than one instruction, just like in C.
221 /* one instruction */
225 /* more than one instruction (braces needed) */
231 'If' conditionals can also include an else instruction or block:
234 print("You are sane\n");
241 'While' conditionals are exactly as you suppose they are:
243 while (player_is_alive) {
250 As in 'if', the loop body needs braces if it has more than one instruction.
255 'Foreach' is a special conditional to do something with all elements of an
256 array. The usual construction is as follows:
259 weekdays = [ 'monday', 'tuesday', 'wednesday', 'thurday', 'friday' ];
261 foreach (w, weekdays)
262 print("I hate ", w, "s\n");
264 Each value of the array will be assigned to the variable and the loop body
265 executed. As always, the variable is created if it doesn't exist.
270 Exit from 'while' and 'foreach' loops can be forced by using 'break', just
279 To assign a value to a variable, use the = operator. Remember that scalars
280 are always assigned by value, and multiple values (arrays and hashes) are
281 always assigned by reference (in case you need a copy of a multiple value,
282 use the clone() function).
287 The usual +, -, *, / and % operators are used for addition, substraction,
288 multiply, divide and modulo, as always. Operands for the modulo operator
289 are treated as integers, and for the rest of them, as real numbers.
290 Operator precedence are like in C; you can always use parentheses to
291 explicitly force your desired precedence.
296 The usual == (equality), != (inequality), > (greater than), < (less than),
297 >= (greater or equal than) and <= (less or equal than) operands can be
303 The 'eq' operator is used for testing string equality, 'ne' for the
304 opposite and ~ is used for concatenating strings.
306 MPSL's scalar values are used for both string and numerical values, so (as
307 in Perl) the string and numeric comparison operators must be different:
310 if (a == b) { /* this is truth */ }
311 if (a eq b) { /* this is false */ }
316 As in C, && (logical and) and || (logical or) are used. They don't return
317 just a boolean value, but the value that matches the condition, so that
321 c = a || b; /* c ends with a value of 100 */
322 c = a && b; /* c ends with a value of 0 */
324 c = a || b; /* c ends with a value of 50 */
325 c = a && b; /* c ends with a value of 100 */
327 MPSL lacks a ternary conditional operator (as the ? : one in C), but it
328 can be easily simulated with && and || operators:
330 /* assigns to c the greatest of a and b */
333 There is also the ! operator, that negates a condition.
338 Immediate operators act directly over variables. The most usual examples
339 are the unary ++ and --, that are used as in C.
342 a++; /* a's value is now 101 */
343 a--; /* back to 100 */
345 Also as in C, this operators can be used as prefixes or suffixes, giving
346 the following result:
349 b = a++; /* b's value is 100, a's value is 101 */
350 c = ++a; /* c's and a's value is both 102 */
352 The well known binary +=, -=, *=, /= and %= also exist:
354 a += 25; /* adds 25 to a */
359 Subroutines (also called functions) are created with the 'sub' keyword:
363 while (!exit_requested) {
372 Subroutines can also accept arguments:
374 sub process_option(o)
379 print("Option is ", o, "\n");
382 Subroutine arguments can be used as local variables (in fact, that is exactly
385 As in assignations, when you pass a multiple value (arrays and hashes) as
386 an argument to a subroutine, it's always done by reference, so modifying
387 it will change the original value:
389 sub dequeue(queue) { local a = pop(queue); do_something_with(a); }
391 my_q = [ 10, 20, 30 ];
392 dequeue(my_q); /* on exit, my_q will contain only [ 10, 20 ] */
394 As every code fragment in MPSL, subroutines always return a value. By
395 default, a subroutine returns the result of the last operation:
397 sub avg(a, b) { a += b; a /= 2; }
399 The value to be returned can be explicitly expressed by using the 'return'
400 keyword, that can also be used to break execution flow:
405 print("Invalid value for b.\n");
412 When calling a subroutine, parentheses are always mandatory, even if it
413 has no arguments. If a subroutine is referenced without its arguments,
414 it's not called, but a pointer to it returned instead:
416 sub sum(a, b) { return a + b; }
418 a = sum(10, 20); /* a == 30 */
419 b = sum; /* b has a pointer to the sum subroutine */
421 c = b(20, 30); /* c == 50, same as calling sum(20, 30) */
423 The 'sub' directive can also be used as an rvalue to define anonymous
424 subroutines. So, the following can be done:
427 push(on_exit_subs, sub { print("Close files\n"); } );
428 push(on_exit_subs, sub { print("Clean up memory\n"); } );
429 push(on_exit_subs, sub { print("Other stuff\n"); } );
431 /* exiting; calling all functions stored in on_exit_subs */
432 foreach (f, on_exit_subs) f();
434 Anonymous functions can also accept arguments:
437 sub (a, b) { print(a, " + ", b, ": ", a + b, "\n"); },
438 sub (a, b) { print(a, " - ", b, ": ", a - b, "\n"); },
439 sub (a, b) { print(a, " * ", b, ": ", a * b, "\n"); },
440 sub (a, b) { print(a, " / ", b, ": ", a / b, "\n"); }
443 foreach (f, math_ops) f(10, 20);
445 This kind of anonymous subroutines are commonly used as callbacks. The
446 following examples use the two-argument version of sort() to sort arrays
449 /* reverse-sort the array (comparing each element backwards) */
450 sorted_ary = sort(unsorted_ary, sub (a, b) { cmp(b, a); } );
452 /* numeric sort (instead of plain ASCII) */
453 sorted_ary = sort(unsorted_ary, sub (a, b) { a - b; } );
455 Subroutines are defined in execution time and *not* in compilation time.
456 This means that you can redefine a subroutine whenever you want, but be
457 aware that you can't use it before the 'sub' instruction has been
458 executed. This is a common pitfall:
460 /* call a function before it exists: error */
461 print("Average for 2 and 3 is ", avg(2, 3), "\n");
463 sub avg(a, b) { a += b; a /= 2; }
465 /* now you can use it */
466 print("Average for 4 and 5 is ", avg(4, 5), "\n");
468 It's easier to see subroutine definitions as an assignation of a code
469 block to a variable: you would never access a variable before assigning a
478 The cmp() function can be used to compare two values. It returns a signed
479 number, negative if the first value is lesser than the second, positive
480 on the contrary or zero if they are the equal. It also can be used to
481 compare arrays and hashes:
483 cmp('a', 'b'); /* < 0 ('a' is lesser than 'b') */
484 cmp('aaa', 'aab'); /* < 0 ('aaa' is lesser than 'aab') */
486 [ 1, 2 ]); /* > 0 ([1,2,3] is greater than [1,2]) */
488 [ 1, "a", 3 ]); /* 0 (both arrays are equal) */
490 Arrays are first tested for number of elements (so bigger arrays are
491 greater than arrays with fewer elements), and if both are equal, then each
492 element is tested sequentially.
494 The split() and join() functions can be used to convert strings into
495 arrays and vice-versa. Examples:
497 /* sets a to [ 12, 'abcd', 356, '', 'xxx' ] */
498 local a = split(':', '12:abcd:356::xxx');
500 /* sets b to 12->abcd->356->->xxx */
501 local b = join('->', a);
503 The split() function can have a special separator, NULL, that makes it
504 explode the string in characters:
506 /* sets c to [ 't', 'h', 'i', 's' ] */
507 local c = split(NULL, "this");
509 The splice() function can be used to delete, insert or replace a subset of
510 a string with another one. It returns a two element array: one with the
511 newly created string, and another with the deleted part. Examples:
513 local a = "This is a string";
515 /* original string, string to be inserted, position, chars to delete */
516 splice(a, 'not', 8, 0); /* [ 'This is not a string', NULL ] */
517 splice(a, '', 5, 3); /* [ 'This a string', 'is ' ] */
518 splice(a, 'can be', 5, 3); /* [ 'This can be a string', 'is ' ] */
520 The chr() and ord() functions return the character represented by a Unicode
521 number and vice-versa:
523 ord('A'); /* returns 65 (ASCII or Unicode for A) */
524 chr(65); /* return 'A' */
526 The sprintf() function works like any other sprintf() implementation in
527 the world: accepts a format string (with special, %-prefixed placeholders)
528 and a list of arguments, and substitutes them.
530 sprintf("%s: %d", 'ERROR', 10); /* returns 'ERROR: 10' */
531 sprintf("%04X", 16384); /* return '4000' */
536 Arrays can be easily manipulated by using push(), pop(), shift(), adel()
542 /* add three values: ary will contain [ 10, 20, 30, 40 ] */
543 push(ary, 10); push(ary, 20); push(ary, 30); push(ary, 40);
545 /* delete and return last value; ary contains now [ 10, 20, 30 ]
546 and top contains 40 */
549 /* shift() deletes from the beginning; ary contains now [ 20, 30 ] */
552 /* ins() inserts an element in an array; ary contains now [ 20, 5, 30 ] */
555 */ adel() does the opposite, delete values; ary is back [ 20, 30 ] */
556 deleted_item = adel(ary, 1);
558 The seek() function searches sequentially for an exact value in an array,
559 returning its offset if found, or -1 otherwise:
561 weekdays = [ 'monday', 'tuesday', 'wednesday', 'thurday', 'friday' ];
564 seek(weekdays, 'wednesday');
566 The sort() function returns a sorted copy of the array sent as argument:
568 sorted_weekdays = sort(weekdays);
570 The sorting is done with the cmp() function (see above); if another kind of
571 sort is wanted, the 2-argument version must be used, as mentioned
572 previously in the _Subroutines_ section.
574 Whenever a change must be done on every element of an array, the map()
575 function can be useful and much faster than iterating the array using
576 foreach() and storing the changes in another one.
578 The first argument of map() can be an executable value accepting one
579 argument, that will be set to each element of the array. The return
580 value will be used as the new value:
582 /* a function to multiply by 10 its unique argument */
583 sub multiply_by_10(val)
588 /* an array of values */
589 a = [ 1, 5, 3, 7, 30, 20 ];
591 /* a_by_10 will contain [10, 50, 30, 70, 300, 200 ] */
592 a_by_10 = map(multiply_by_10, a);
594 Of course, the executable value can be an anonymous subroutine:
596 /* Creates a zero-filled version of the numbers in a */
597 a_zero_filled = map( sub(e) { sprintf("%04d", e); }, a);
599 The first argument of map() can also be a hash to directly
602 /* numerals as keys, names as values */
603 english_nums = { 1 => "one", 2 => "two", 3 => "three" };
605 /* translated_nums will have [ "one", "two", "three" ] */
606 translated_nums = map(english_nums, [ 1, 2, 3 ]);
608 Another powerful array function is grep(); it matches a regular
609 expression on an array and returns a new one containing all
610 elements that matched:
612 a = [ 1, 9, "mix190", 4, "foo", 9000 ];
614 /* b is [ 9, "mix190", 9000 ] */
617 The first argument of grep() can also be an executable value,
618 that will accept each element of the array on each call. The
619 output array will contain all elements for which the function
622 /* return all elements greater than 10 */
623 a = [ 1, 45, 20, 4, 0, 1000 ];
625 /* b is [ 45, 20, 1000 ] */
626 b = grep( sub(e) { e > 10; }, a);
628 If no element were generated, NULL is returned (instead of
631 Other lower level array functions are expand() and collapse().
632 The expand() function opens space in an array:
634 ary = [ 1, 2, 3, 4 ];
636 /* ary will have two more elements at offset 3,
637 containing [ 1, 2, 3, NULL, NULL, 4 ] */
640 On the opposite, collapse() deletes space:
642 /* deletes 3 elements at offset 1: ary is now [ 1, NULL, 4 ] */
645 Take note that expand() and collapse() manipulate the array
646 directly (i.e. they don't return a new array).
651 The hsize() function returns the number of pairs in a hash:
654 num = hsize( { 1 => 'one', 2 => 'two', 3 => 'three' });
656 Take note that size() cannot be used for this purpose, as it returns the
657 number of buckets in the hash (which is probably of no use for you).
659 If the existence of a pair must be tested, the exists() function is handy:
661 h = { 'a' => 1000, 'b' => 0, 'c' => 3000 };
664 if (exists(h, 'b')) print("B exists\n");
666 /* this is not, as 0 does not evaluates as true */
667 if (h['b']) print("B is true\n");
669 The keys() function returns an array with the keys of a hash:
671 /* will contain [ 'a', 'b', 'c' ] */
674 The hdel() function deletes a pair given its key. The deleted value is
677 /* deletes 'c' and returns its value (3000) */
678 c_value = hdel(h, 'c');
680 Type-checking functions
681 ~~~~~~~~~~~~~~~~~~~~~~~
683 There are three functions to test a type of a value: is_exec(), is_hash()
684 and is_array(). They return true if the tested value is executable, a hash
685 or an array, respectively.
687 On this implementation, executable and hash values are also arrays, so if
688 you need to act differently on the type of a value, the correct order is
689 is_exec(), is_hash() and is_array(), as in the following example:
691 if (is_exec(v)) { print("v is executable\n"); }
693 if (is_hash(v)) { print("v is a hash with ", hsize(v), " pairs\n"); }
695 if (is_array(v) { print("v is an array with ", size(v), " elements\n"); }
697 print("v is a scalar\n");
699 Regular expression matching
700 ---------------------------
702 Regular expression matching is done with the regex() function. In the simpler
703 of its forms, it can be used to test if a string matches:
705 /* hours, minutes, seconds */
708 if (regex("/^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/", v))
709 print("The v variable contains a valid time\n");
711 The regular expression can contain flags; those are 'i', for case
712 insensitiveness, 'l', to select the last matching instead of the first,
713 or 'm', to treat the string as a multiline one (i.e., one containing \n
714 characters), where the special ^ and $ markup match beginning and end of
715 lines and not the beginning or end of the string.
717 Regex() returns the matched string.
719 v = "The value of PI is 3.1416, more or less";
721 pi = regex("/[0-9]+\.[0-9]+/", v);
723 If regex() is called without arguments, it returns the last match as an array
724 of two elements; the first contain the offset of the matched strings, and the
725 second, the size in characters of it. If last match was unsuccessful, NULL is
728 /* get the match of the previous example */
732 print(coords[0], ":", coords[1], "\n");
734 Regex() can include an optional third argument, the offset where the regular
735 expression matching must start (instead of 0, the beginning of the string).
736 This can be used to extract many values from the same string:
738 /* lets extract all numbers in the following string: */
739 s = "There is 10 and 35 and 42 in the number 103542!";
742 while (n = regex("/[0-9]+/", s, offset)) {
748 /* get the coordinates */
751 /* start from there (previous match offset + size) */
752 offset += c[0] + c[1];
755 For more complex situations, the first argument of regex() can be an array
756 of regular expressions (instead of a string). Those expressions will tried
757 one after the other on the string, each one using the offset returned by
758 the previous one. If all of them are matched, an array with the matched strings
761 /* match pairs of key=value commands, with many variants */
763 v2 = " KEY2 = value2";
766 /* array regex: a regex for each part */
767 r = regex([ "/\s*/", /* possible leading blanks (0) */
768 "/[a-z0-9]+/i", /* the key (1) */
769 "/\s*=\s*/", /* optional blanks, the = , more blanks (2) */
770 "/[a-z0-9]+/i" /* the value (3) */
774 /* the key is the element #1 and the value the #3 */
779 Regular expression substitutions
780 --------------------------------
782 The sregex() function can be used to substitute the matching part of a
783 string with another string. The simplest form:
785 /* substitute all characters in password with asterisks */
786 sregex('/./g', password, '*');
788 The substitution part can also be a hash:
790 /* substitute \n, \r, etc with their equivalents */
791 sregex("/\\[rnt]/g", var, {
799 /* zero-pad all numbers in var */
800 sregex('/[0-9]+/g', var, sub (m) {
804 The regular expression can contain flags; those are 'i', for
805 case-insensitive matching, and 'g', for global replacements (all ocurrences
806 in the string will be replaced, instead of just the first found).
808 Input/Output operations
809 -----------------------
811 File operations are done by opening files with the open() call. It accepts
812 two arguments, the file and the mode:
814 /* open in read mode */
815 local i = open('existingdata.dat', 'r');
817 /* open in write mode (create) */
818 local o = open('newdata.dat', 'w');
820 The opening mode is the same as the one in the fopen() C library call, so
821 other combinations exist.
823 If the file cannot be open or created, NULL is returned.
825 The read() function returns a line read from a file descriptor, or NULL if
826 no more lines can be read (i.e. on EOF). A line is considered from the
827 current file position until an end of line mark (\n or \r\n). All files
828 under MPSL are considered as text ones; before the read() call returns, the
829 string is converted to wide chars (the internal representation of strings
830 in MPSL) by using the current locale definitions, unless a explicit
831 encoding is set by calling encoding() (see below).
833 The opposite of read() is write(); it accepts a file descriptor and a
834 string to be written. As read(), the string is converted from wide chars by
835 using the current locale definitions unless a different encoding() was set.
836 The write() function does not write an end of line, though.
838 Similar functions getchar() and putchar() exist to read and write
839 characters instead of lines. This functions don't do any locale nor
840 encoding conversions.
842 The unlink() function can be used to delete files, chmod() to set the mode
843 and chown() to set the owner.
845 The stat() function returns an array containing information about a file,
846 similar to the C library function of the same name. The returned values
847 are: device number, inode, mode, number of links, uid, gid, rdev, size,
848 atime, mtime and ctime. Take note that not all values has meaning depending
849 on the filesystem or the architecture. The `mode' argument can be used in
850 chmod() and `uid' and `gid' in chown(). If the file does not exist, stat()
851 returns NULL (which is a good way to test for file existence).
853 The glob() function accepts a file spec as the only argument and returns
854 an array of filenames matching it. Directories have a / as the last
855 character. The file spec and the returned files are system-dependent, but
856 always usable by open().
858 The popen() and pclose() function calls are used for piping from / to
859 programs. Pipes can be open for reading ('r' mode), for writing ('w' mode),
860 or bidirectional (by appending '+' to the mode, which can be used to
861 communicate two-way with programs like ispell, smtp servers and such). Once
862 open, the read() and write() functions can be used the same as in plain
865 As mentioned above, the encoding() function can be used to force the
866 reading or writing conversions to be done when doing IO. By default, the
867 current locale is used, and it's the same as calling encoding() without
868 arguments. If an encoding is forced, reading and writing is done by using
869 the selected converter. Take note that support for the `iconv' library must
870 be compiled in; if it's not, a special, ad-hoc converter called "utf-8"
873 Each file can have a different encoding converter and is selected at open()
876 A snippet to convert a file from current locale to iso8859-1 can be:
878 sub convert_to_iso8859_1(fromfile, tofile)
883 /* open the file first */
884 if ((i = open(fromfile, 'r')) == NULL)
887 /* set encoding to iso8859-1 (can fail) */
888 if (encoding("iso8859-1") < 0) {
893 /* create the new file now; it will have iso8859-1
894 encoding as it's the last encoding set. The input
895 file keeps its original encoding */
896 if ((o = open(tofile, 'w')) != NULL) {
905 /* close input and revert to default encoding */
912 The load() function can be used to load, compile and execute an MPSL
913 source file. The file will be searched for using the paths in the INC
922 Stores the command line arguments sent to the main() function.
927 Holds an array of paths on disk where source files will be searched
928 for by the load() command.
933 Stores the last severe error message (compilation errors, etc.).
938 Stores the last error message from the system (file not found, etc.).
940 STDIN, STDOUT, STDERR
941 ~~~~~~~~~~~~~~~~~~~~~
943 The famous standard file descriptors. Can be used in read(), write()
944 and related functions.
949 The home directory for the current user. It's supposed to be a writable
950 directory where users can store their configuration and documents.
955 The application directory.
960 Stores the MPSL version as a string.
965 This is an accessor / mutator function that allows to retrieve information
966 and tune some values for the MPDM (Minimum Profit Data Manager). If called
967 without arguments, the current values are returned. A hash can be sent as
968 argument to change some of them. These are the keys:
970 * count: Total number of values being managed (read only).
971 * low_threshold: The minimum number of values to be managed to start
972 doing garbage collection (read / write).
973 * default_sweep: The number of values that will be tested for garbage
974 collection on each execution cycle (read / write).
975 * memory_usage: The approximate size in bytes of the memory managed by
977 * hash_buckets: The default number of buckets a hash will use. It must
978 be a prime number (read / write).
979 * referenced: The number of values being managed that are referenced. The
980 rest of them in count are candidate for garbage collection (read only).
982 The default values are the best for normal usage. Of course, you only must
983 change any of them if you know what you are doing.
987 /* set a bigger value for hash buckets */
988 MPDM( { 'hash_buckets' => 127 });
990 /* dump current setup */
994 Angel Ortega <angel@triptico.com>