File: script.h

package info (click to toggle)
warzone2100 2.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 104,520 kB
  • ctags: 37,273
  • sloc: ansic: 194,169; yacc: 6,307; sh: 4,753; lex: 1,943; makefile: 1,507; cpp: 836; perl: 139
file content (227 lines) | stat: -rw-r--r-- 7,364 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
	This file is part of Warzone 2100.
	Copyright (C) 1999-2004  Eidos Interactive
	Copyright (C) 2005-2010  Warzone 2100 Project

	Warzone 2100 is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	Warzone 2100 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Warzone 2100; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
 * Script.h
 *
 * Interface to the script library
 */
#ifndef _script_h
#define _script_h

#include "interpreter.h"
#include "stack.h"
#include "codeprint.h"
#include "parse.h"
#include "event.h"
#include "eventsave.h"

/* Whether to include debug info when compiling */
typedef enum _scr_debugtype
{
	SCR_DEBUGINFO,		// Generate debug info
	SCR_NODEBUG,		// Do not generate debug info
} SCR_DEBUGTYPE;

// If this is defined we save out the compiled scripts
#define SCRIPTTYPE SCR_DEBUGINFO

// Initialise the script library
extern BOOL scriptInitialise(void);

// Shutdown the script library
extern void scriptShutDown(void);

/***********************************************************************************
 *
 * Compiler setup functions
 */

/* Set the type table */
extern void scriptSetTypeTab(TYPE_SYMBOL *psTypeTab);

/* Set the function table */
extern void scriptSetFuncTab(FUNC_SYMBOL *psFuncTab);

/* Set the external variable table */
extern void scriptSetExternalTab(VAR_SYMBOL *psExtTab);

/* Set the object variable table */
extern void scriptSetObjectTab(VAR_SYMBOL *psObjTab);

/* Set the constant table */
extern void scriptSetConstTab(CONST_SYMBOL *psConstTab);

/* Set the callback table */
extern void scriptSetCallbackTab(CALLBACK_SYMBOL *psCallTab);

/* Set the type equivalence table */
extern void scriptSetTypeEquiv(TYPE_EQUIV *psTypeTab);


/***********************************************************************************
 *
 * Return stack stuff
 */

/**
 * Current call depth
 *
 * \return Number of calls on the return address stack
 */
extern UDWORD retStackCallDepth(void);


/***********************************************************************************
 *
 * Compiler functions
 */

/** Compile a script program
 *  \param fileHandle a PhysicsFS file handle to the script-file to compile
 *  \param debugType whether debugging information should be generated or not.
 *                   Select \c SCR_DEBUGINFO to generate debugging information,
 *                   choose any other parameter if you don't want debugging
 *                   information attached.
 *  \return a valid, non-null pointer on success,
 *          otherwise a null pointer on failure.
 */
extern SCRIPT_CODE* scriptCompile(PHYSFS_file* fileHandle, SCR_DEBUGTYPE debugType);

/* Free a SCRIPT_CODE structure */
extern void scriptFreeCode(SCRIPT_CODE *psCode);

/* Lookup a script variable */
extern BOOL scriptGetVarIndex(SCRIPT_CODE *psCode, char *pID, UDWORD *pIndex);

/* returns true if passed INTERP_TYPE is used as a pointer in INTERP_VAL, false otherwise */
extern BOOL scriptTypeIsPointer(INTERP_TYPE type);

extern const char *scriptTypeToString(INTERP_TYPE type) WZ_DECL_PURE;
extern const char *scriptOpcodeToString(OPCODE opcode) WZ_DECL_PURE;
extern const char *scriptFunctionToString(SCRIPT_FUNC function) WZ_DECL_PURE;

/* Run a compiled script */
extern BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType,
							UDWORD index, UDWORD offset);


/***********************************************************************************
 *
 * Event system functions
 */

// reset the event system
extern void eventReset(void);

// Initialise the create/release function array - specify the maximum value type
extern BOOL eventInitValueFuncs(SDWORD maxType);

// a create function for data stored in an INTERP_VAL
typedef BOOL (*VAL_CREATE_FUNC)(INTERP_VAL *psVal);

// a release function for data stored in an INTERP_VAL
typedef void (*VAL_RELEASE_FUNC)(INTERP_VAL *psVal);

// Add a new value create function
extern BOOL eventAddValueCreate(INTERP_TYPE type, VAL_CREATE_FUNC create);

// Add a new value release function
extern BOOL eventAddValueRelease(INTERP_TYPE type, VAL_RELEASE_FUNC release);

// Create a new context for a script
extern BOOL eventNewContext(SCRIPT_CODE *psCode,
							CONTEXT_RELEASE release, SCRIPT_CONTEXT **ppsContext);

// Copy a context, including variable values
extern BOOL eventCopyContext(SCRIPT_CONTEXT *psContext, SCRIPT_CONTEXT **ppsNew);

// Add a new object to the trigger system
// Time is the application time at which all the triggers are to be started
extern BOOL eventRunContext(SCRIPT_CONTEXT *psContext, UDWORD time);

// Remove a context from the event system
extern void eventRemoveContext(SCRIPT_CONTEXT *psContext);

// Set a global variable value for a context
extern BOOL eventSetContextVar(SCRIPT_CONTEXT *psContext, UDWORD index,
							   INTERP_VAL *data);

// Get the value pointer for a variable index
extern BOOL eventGetContextVal(SCRIPT_CONTEXT *psContext, UDWORD index,
							   INTERP_VAL **ppsVal);

// Process all the currently active triggers
// Time is the application time at which all the triggers are to be processed
extern void eventProcessTriggers(UDWORD currTime);

// Activate a callback trigger
extern void eventFireCallbackTrigger(TRIGGER_TYPE callback);

/***********************************************************************************
 *
 * Support functions for writing instinct functions
 */

/* Pop a number of values off the stack checking their types
 * This is used by instinct functions to get their parameters
 * The varargs part is a set of INTERP_TYPE, UDWORD * pairs.
 * The value of the parameter is stored in the DWORD pointed to by the UDWORD *
 */
extern BOOL stackPopParams(unsigned int numParams, ...);

/* Push a value onto the stack without using a value structure */
extern BOOL stackPushResult(INTERP_TYPE type, INTERP_VAL *result);

/***********************************************************************************
 *
 * Script library instinct functions
 *
 * These would be declared in the function symbol array:
 *
 *	{ "traceOn",				interpTraceOn,			VAL_VOID,
 *		0, { VAL_VOID } },
 *	{ "traceOff",				interpTraceOff,			VAL_VOID,
 *		0, { VAL_VOID } },
 *	{ "setEventTrigger",		eventSetTrigger,		VAL_VOID,
 *		2, { VAL_EVENT, VAL_TRIGGER } },
 *	{ "eventTraceLevel",		eventSetTraceLevel,		VAL_VOID,
 *		1, { VAL_INT } },
 *
 */

/* Instinct function to turn on tracing */
extern BOOL interpTraceOn(void);

/* Instinct function to turn off tracing */
extern BOOL interpTraceOff(void);

// Change the trigger assigned to an event
// This is an instinct function that takes a VAL_EVENT and VAL_TRIGGER as parameters
extern BOOL eventSetTrigger(void);

// set the event tracing level
//   0 - no tracing
//   1 - only fired triggers
//   2 - added and fired triggers
//   3 - as 2 but show tested but not fired triggers as well
extern BOOL eventSetTraceLevel(void);

#endif