MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | CONCEPT |
| 2 | lfuns |
| 3 | |
| 4 | DESCRIPTION |
| 5 | A lfun is a LPC function within an object which is public and can |
| 6 | be called by other objects. In OO terms, lfuns are "methods" |
| 7 | which you can send "messages" to. |
| 8 | |
| 9 | Calling lfuns is done by using the efun call_other(), which |
| 10 | takes as arguments the object in which the lfun is to be called, |
| 11 | the name of the lfun to be called in the object, and additional |
| 12 | and optional arguments. |
| 13 | |
| 14 | An example looks like this: |
| 15 | |
Zesstra | 98e90af | 2021-05-07 19:18:04 +0200 | [diff] [blame] | 16 | call_other(drink, "QueryShort"); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | |
| 18 | This call may also be written as |
| 19 | |
Zesstra | 98e90af | 2021-05-07 19:18:04 +0200 | [diff] [blame] | 20 | drink->QueryShort(); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 21 | |
| 22 | This means call_other(object, "function", args...) can also be |
| 23 | written as object->function(args...). The second form is |
| 24 | preferred as it is easier to read. |
| 25 | |
Zesstra | 98e90af | 2021-05-07 19:18:04 +0200 | [diff] [blame] | 26 | call_other() will return 0, if the function does not exist |
| 27 | or is not accessible. As an alternative there is call_strict() |
| 28 | which will result in an error in such a case. The call is |
| 29 | similar: |
| 30 | |
| 31 | call_strict(drink, "QueryShort") |
| 32 | |
| 33 | And can be written as |
| 34 | |
| 35 | drink.QueryShort(); |
| 36 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 37 | Some lfuns have a special meaning for the LPC driver, because |
| 38 | they are applied by the interpreter instead from an LPC object. |
| 39 | To distinguish those, they are called ``applied lfuns''. |
| 40 | |
| 41 | SEE ALSO |
| 42 | efuns(LPC), efun(E), applied(A), master(M), call_other(E) |