-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrb_comp.native.c
261 lines (208 loc) · 6.48 KB
/
rb_comp.native.c
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* -MODULE----------------------------------------------------------------------
RapidBATCH
Copyright (C) 2008, 2009 by Phorward Software Technologies, Jan Max Meyer
http://www.phorward-software.com ++ [email protected]
File: rb_comp.native.c
Author: Jan Max Meyer
Usage: Native scripting function management
----------------------------------------------------------------------------- */
/*
* Includes
*/
#include "rb_global.h"
/*
* Global variables
*/
/*
* Functions
*/
/* -FUNCTION--------------------------------------------------------------------
Function: rb_add_native_function()
Author: Jan Max Meyer
Usage: Sets up a new native function to be called from within
RapidBATCH scripts.
Parameters: char* name The name of the native
build-in function
rb_native_func fct Pointer to the build-in
function
pboolean isfunc Defines if the user-function
is threaded as a function
or a procedure.
char* parmdef Parameter definition; This
defines the number
and type of the
parameters to be
checked.
"v" Parameter by value
"p" Parameter by ref
"+" Variable list of
parameters following
pboolean compiletime TRUE: Function is a compile-
time function and is
executed at compile
time
FALSE: Function is a runtime
function and is exe-
cuted at run-time
Returns: long Returns 0 on
success.
Else, -1 is
returned in case if the
function already exists,
and -1 when
parameters are missing.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
int rb_add_native_function( char* name, rb_native_func fct,
pboolean isfunc, char* parmdef, int run_at )
{
symbol* sym;
PROC( "rb_add_native_function" );
PARMS( "name", "%s", name );
PARMS( "fct", "%p", fct );
PARMS( "isfunc", "%s", BOOLEAN_STR( isfunc ) );
PARMS( "parmdef", "%s", parmdef );
PARMS( "run_at", "%d", run_at );
if( !( name && *name && fct && parmdef ) )
{
MSG( "There is something wrong with your parameters" );
RETURN( -1 );
}
MSG( "Adding symbol table entry" );
if( !rb_symtab_find( name, SYM_PROC ) )
{
MSG( "Symbol doesn't exist, fine!" );
if( !( sym = rb_symtab_new( name, SYM_PROC ) ) )
{
MSG( "Failed to create new symbol" );
RETURN( -1 );
}
sym->native = TRUE;
sym->global = TRUE;
sym->defined = TRUE;
sym->used = TRUE;
sym->patched = TRUE;
sym->constant = run_at;
sym->function = isfunc;
sym->offset.function = fct;
if( !( sym->parmdef = (char*)pstrdup( parmdef ) ) )
{
MSG( "Failed to allocate memory for parmdef" );
RETURN( -1 );
}
RETURN( 0 );
}
MSG( "The function already exists!" );
RETURN( -1 );
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_add_native_var()
Author: Jan Max Meyer
Usage: Sets up a new native variable to be called from within
RapidBATCH scripts.
Parameters: char* name The name of the native
build-in variable.
rb_native_var get Pointer to the variable
get function
rb_native_var set Pointer to the variable
set function
Returns: int Returns 0 on
success.
Else, -1 is
returned in case if the
function already exists,
and -1 when
parameters are missing.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
int rb_add_native_var( char* name, rb_native_var get, rb_native_var set )
{
symbol* sym;
PROC( "rb_add_native_var" );
PARMS( "name", "%s", name );
PARMS( "get", "%p", get );
PARMS( "set", "%p", set );
if( !( name && *name ) )
{
MSG( "There is something wrong with your parameters" );
RETURN( -1 );
}
MSG( "Adding symbol table entry" );
if( !rb_symtab_find( name, SYM_VAR ) )
{
MSG( "Symbol doesn't exist, fine!" );
if( !( sym = rb_symtab_new( name, SYM_VAR ) ) )
{
MSG( "Failed to create new symbol" );
RETURN( -1 );
}
sym->native = TRUE;
sym->global = TRUE;
sym->defined = TRUE;
sym->used = TRUE;
sym->offset.variable.get = get;
sym->offset.variable.set = set;
RETURN( 0 );
}
RETURN( -1 );
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_add_native_const()
Author: Jan Max Meyer
Usage: Sets up a new native constant variable for its usage within
scripts.
Parameters: char* name The name of the native
build-in variable.
char* value The constant value; This
is always string, and will
be converted to a better
suiting type (if possible!)
during compile time.
pboolean dup_val Specifies if 'value' shall
be duplicated into a newly
allocated address.
Returns: int Returns 0 on
success.
Else, -1 is
returned in case if the
function already exists,
and -1 when
parameters are missing.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
int rb_add_native_const( char* name, char* value, pboolean dup_val )
{
symbol* sym;
PROC( "rb_add_native_const" );
PARMS( "name", "%s", name );
PARMS( "value", "%s", value );
if( !( name && *name && value ) )
{
MSG( "There is something wrong with your parameters" );
RETURN( -1 );
}
MSG( "Adding symbol table entry" );
if( !rb_symtab_find( name, SYM_VAR ) )
{
MSG( "Symbol doesn't exist, fine!" );
if( !( sym = rb_symtab_new( name, SYM_VAR ) ) )
{
MSG( "Failed to create new symbol" );
RETURN( -1 );
}
sym->native = TRUE;
sym->global = TRUE;
sym->constant = TRUE;
sym->defined = TRUE;
sym->used = TRUE;
if( dup_val )
sym->offset.constant = pstrdup( value );
else
sym->offset.constant = value;
RETURN( 0 );
}
RETURN( -1 );
}