root/1.8.3/tags/p6/hdrs/function.h

Revision 1032, 4.1 KB (checked in by shawnw, 18 months ago)

Merged 1.8.3p4 into trunk

Line 
1#ifndef _FUNCTIONS_H_
2#define _FUNCTIONS_H_
3
4#include "copyrite.h"
5
6#define FN_REG 0x0
7/* Function arguments aren't parsed */
8#define FN_NOPARSE      0x1
9#define FN_LITERAL      0x2
10#define FN_ARG_MASK     0x3
11/* Function is disabled */
12#define FN_DISABLED     0x4
13/* Function will fail if object is gagged */
14#define FN_NOGAGGED  0x8
15/* Function will fail if object is a guest */
16#define FN_NOGUEST   0x10
17/* Function will fail if object is fixed */
18#define FN_NOFIXED   0x20
19/* Function is wizard-only */
20#define FN_WIZARD 0x40
21/* Function is royalty or wizard */
22#define FN_ADMIN  0x80
23/* Function is god-only */
24#define FN_GOD    0x100
25/* Function is builtin */
26#define FN_BUILTIN 0x200
27/* Function can be overridden with a @function */
28#define FN_OVERRIDE 0x400
29/* Side-effect version of function no workie */
30#define FN_NOSIDEFX 0x800
31/* Log function name */
32#define FN_LOGNAME 0x1000
33/* Log function name and args */
34#define FN_LOGARGS 0x2000
35/* Localize function registers */
36#define FN_LOCALIZE     0x4000
37/* Allowed in @function only */
38#define FN_USERFN     0x8000
39
40#ifndef HAVE_FUN_DEFINED
41typedef struct fun FUN;
42#define HAVE_FUN_DEFINED
43#endif
44
45typedef void (*function_func) (FUN *, char *, char **, int, char *[], int[],
46                               dbref, dbref, dbref, const char *, PE_Info *);
47
48/** A calling pointer to a function.
49 * This union holds either a pointer to a function's code or
50 * the offset of the function in the user-defined function table.
51 */
52union fun_call {
53  function_func fun;    /**< Pointer to compiled function code */
54  size_t offset;        /**< Offset into user-defined function table */
55};
56
57/** A function.
58 * This structure represents a mushcode function.
59 */
60struct fun {
61  const char *name;     /**< Function name */
62  union fun_call where; /**< Where to find the function to call it */
63  int minargs;          /**< Minimum arguments required, or 0 */
64  /** Maximum arguments allowed.
65   * Maximum arguments allowed. If there is no limit, this is INT_MAX.
66   * If this is negatve, the final argument to the function can contain
67   * commas that won't be parsed, and the maximum number of arguments
68   * is the absolute value of this variable.
69   */
70  int maxargs;
71  unsigned int flags;   /**< Bitflags of function */
72};
73
74typedef struct userfn_entry USERFN_ENTRY;
75
76/** A user-defined function
77 * This structure represents an entry in the user-defined function table.
78 */
79struct userfn_entry {
80  char *fn;             /**< Name of the function */
81  dbref thing;          /**< Dbref of object where the function is defined */
82  char *name;           /**< Name of attribute where the function is defined */
83  unsigned int flags;   /**< Bitflags of function */
84};
85
86USERFN_ENTRY *userfn_tab;
87
88void do_userfn(char *buff, char **bp,
89               dbref obj, ATTR *attrib,
90               int nargs, char **args,
91               dbref executor, dbref caller, dbref enactor,
92               PE_Info *pe_info, int extra_flags);
93
94FUN *func_hash_lookup(const char *name);
95FUN *builtin_func_hash_lookup(const char *name);
96int check_func(dbref player, FUN *fp);
97int restrict_function(const char *name, const char *restrict);
98int alias_function(const char *function, const char *alias);
99void do_function_restrict(dbref player, const char *name,
100                          const char *restrict, int builtin);
101void do_function_restore(dbref player, const char *name);
102void do_list_functions(dbref player, int lc);
103char *list_functions(const char *);
104void do_function(dbref player, char *name, char **argv, int preserve);
105void do_function_toggle(dbref player, char *name, int toggle);
106void do_function_report(dbref player, char *name);
107void do_function_delete(dbref player, char *name);
108void function_init_postconfig(void);
109
110
111#define FUNCTION_PROTO(fun_name) \
112  extern void fun_name (FUN *fun, char *buff, char **bp, int nargs, char *args[], \
113                   int arglen[], dbref executor, dbref caller, dbref enactor, \
114                   char const *called_as, PE_Info *pe_info)
115extern void function_add(const char *name, function_func fun, int minargs,
116                         int maxargs, int ftype);
117
118#endif
Note: See TracBrowser for help on using the browser.