r8397: merged an upstream fix for the expression bug tpot found yesterday
[ira/wip.git] / source4 / lib / ejs / ejs.h
1 /*
2  *      @file   ejs.h
3  *      @brief  Primary Embedded Javascript (ECMAScript) header.
4  *      @overview This Embedded Javascript (EJS) header defines the 
5  *              public API. This API should only be used by those directly 
6  *              using EJS without using Embedded Server Pages (ESP). ESP 
7  *              wraps all relevant APIs to expose a single consistent API.
8  *              \n\n
9  *              This API requires the mpr/var.h facilities to create and 
10  *              manage objects and properties. 
11  */
12 /********************************* Copyright **********************************/
13 /*
14  *      @copy   default.g
15  *      
16  *      Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
17  *      Portions Copyright (c) GoAhead Software, 1995-2000. All Rights Reserved.
18  *      
19  *      This software is distributed under commercial and open source licenses.
20  *      You may use the GPL open source license described below or you may acquire 
21  *      a commercial license from Mbedthis Software. You agree to be fully bound 
22  *      by the terms of either license. Consult the LICENSE.TXT distributed with 
23  *      this software for full details.
24  *      
25  *      This software is open source; you can redistribute it and/or modify it 
26  *      under the terms of the GNU General Public License as published by the 
27  *      Free Software Foundation; either version 2 of the License, or (at your 
28  *      option) any later version. See the GNU General Public License for more 
29  *      details at: http://www.mbedthis.com/downloads/gplLicense.html
30  *      
31  *      This program is distributed WITHOUT ANY WARRANTY; without even the 
32  *      implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
33  *      
34  *      This GPL license does NOT permit incorporating this software into 
35  *      proprietary programs. If you are unable to comply with the GPL, you must
36  *      acquire a commercial license to use this software. Commercial licenses 
37  *      for this software and support services are available from Mbedthis 
38  *      Software at http://www.mbedthis.com 
39  *      
40  *      @end
41  */
42 /********************************** Includes **********************************/
43
44 #ifndef _h_EJS
45 #define _h_EJS 1
46
47 #include        "miniMpr.h"
48 #include        "var.h"
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 /********************************* Prototypes *********************************/
55
56 typedef MprVarHandle    EjsId;
57 typedef MprVarHandle    EjsHandle;
58
59 /*
60  *      Multithreaded lock routines
61  */
62 typedef void (*EjsLock)(void *lockData);
63 typedef void (*EjsUnlock)(void *lockData);
64
65 /********************************* Prototypes *********************************/
66 /*
67  *      Module management
68  */
69 extern int              ejsOpen(EjsLock lock, EjsUnlock unlock, void *lockData);
70 extern void     ejsClose(void);
71 extern EjsId    ejsOpenEngine(EjsHandle primaryHandle, EjsHandle altHandle);
72 extern void             ejsCloseEngine(EjsId eid);
73
74 /*
75  *      Evaluation functions
76  */
77 extern int              ejsEvalFile(EjsId eid, char *path, MprVar *result, char **emsg);
78 extern int              ejsEvalScript(EjsId eid, char *script, MprVar *result,
79                                         char **emsg);
80 extern int              ejsRunFunction(int eid, MprVar *obj, const char *functionName, 
81                                         MprArray *args);
82
83 /*
84  *      Composite variable get / set routines. Can also use the MPR property
85  *      routines on an object variable.
86  */
87 extern MprVar   ejsCreateObj(const char *name, int hashSize);
88 extern MprVar   ejsCreateArray(const char *name, int hashSize);
89 extern bool             ejsDestroyVar(MprVar *obj);
90 extern int              ejsCopyVar(EjsId eid, const char *var, MprVar *value, 
91                                         bool copyRef);
92 extern int              ejsReadVar(EjsId eid, const char *var, MprVar *value);
93 extern int              ejsWriteVar(EjsId eid, const char *var, MprVar *value);
94 extern int              ejsWriteVarValue(EjsId eid, const char *var, MprVar value);
95 extern int              ejsDeleteVar(EjsId eid, const char *var);
96
97 extern MprVar   *ejsGetLocalObject(EjsId eid);
98 extern MprVar   *ejsGetGlobalObject(EjsId eid);
99
100 /*
101  *      Function routines
102  */
103 extern void     ejsDefineFunction(EjsId eid, const char *functionName, 
104                                         char *args, char *body);
105 extern void     ejsDefineCFunction(EjsId eid, const char *functionName, 
106                                         MprCFunction fn, void *thisPtr, int flags);
107 extern void             ejsDefineStringCFunction(EjsId eid, const char *functionName, 
108                                         MprStringCFunction fn, void *thisPtr, int flags);
109 extern void     *ejsGetThisPtr(EjsId eid);
110 extern MprVar   *ejsGetReturnValue(EjsId eid);
111 extern int              ejsGetLineNumber(EjsId eid);
112 extern int              ejsParseArgs(int argc, char **argv, char *fmt, ...);
113 extern void     ejsSetErrorMsg(EjsId eid, const char* fmt, ...) 
114                                         PRINTF_ATTRIBUTE(2,3);
115 extern void             ejsSetReturnValue(EjsId eid, MprVar value);
116 extern void             ejsSetReturnString(EjsId eid, const char *str);
117
118 #ifdef __cplusplus
119 }
120 #endif
121 #endif /* _h_EJS */
122
123 /*****************************************************************************/
124
125 /*
126  * Local variables:
127  * tab-width: 4
128  * c-basic-offset: 4
129  * End:
130  * vim:tw=78
131  * vim600: sw=4 ts=4 fdm=marker
132  * vim<600: sw=4 ts=4
133  */