-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaWrappers.hh
More file actions
527 lines (476 loc) · 11 KB
/
LuaWrappers.hh
File metadata and controls
527 lines (476 loc) · 11 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/*
* Copyright (C) 2008 Valentin Ziegler, ExactCODE GmbH
* Copyright (C) 2008-2010 René Rebe, ExactCODE GmbH
*
* This program 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; version 2. A copy of the GNU General
* Public License can be found in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT-
* ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* Alternatively, commercial licensing options are available from the
* copyright holder ExactCODE GmbH Germany.
*/
// The aim of this file is to create code for
// FunctionWrapper_*_* and MethodWrapper_*_* classes
// as well as the Call_*_* functions
// Hint: if you want a more readable version of this file,
// use g++ -E
// Sorry for the grave hack,
// c++ templates definitly suck at variadic signatures...
// please port me to the next c++ standard !!
// the macro hackery in this file iterates from N = 7 to N = 0
// and includes this file once for each iteration.
// name(X) is X##N
// ai(X) is "X" if i <= N, ignored otherwise
// aic(X) is ",X" if i <= N, ignored otherwise
// comma is "," if i >= 0
// a0(X) is "X" if i == 0
#ifndef N
#define N 8
#define comma ,
#define a0(X)
#define a1(X) X
#define a1c(X) ,X
#define a2(X) X
#define a2c(X) ,X
#define a3(X) X
#define a3c(X) ,X
#define a4(X) X
#define a4c(X) ,X
#define a5(X) X
#define a5c(X) ,X
#define a6(X) X
#define a6c(X) ,X
#define a7(X) X
#define a7c(X) ,X
#define a8(X) X
#define a8c(X) ,X
#define name(X) X##8
#elif N > 7
#undef N
#undef name
#undef a8
#undef a8c
#define N 7
#define a8(X)
#define a8c(X)
#define name(X) X##7
#elif N > 6
#undef N
#undef name
#undef a7
#undef a7c
#define N 6
#define a7(X)
#define a7c(X)
#define name(X) X##6
#elif N > 5
#undef N
#undef name
#undef a6
#undef a6c
#define N 5
#define a6(X)
#define a6c(X)
#define name(X) X##5
#elif N > 4
#undef N
#undef name
#undef a5
#undef a5c
#define N 4
#define a5(X)
#define a5c(X)
#define name(X) X##4
#elif N > 3
#undef N
#undef name
#undef a4
#undef a4c
#define N 3
#define a4(X)
#define a4c(X)
#define name(X) X##3
#elif N > 2
#undef N
#undef name
#undef a3
#undef a3c
#define N 2
#define a3(X)
#define a3c(X)
#define name(X) X##2
#elif N > 1
#undef N
#undef name
#undef a2
#undef a2c
#define N 1
#define a2(X)
#define a2c(X)
#define name(X) X##1
#elif N > 0
#undef N
#undef comma
#undef name
#undef a1
#undef a1c
#define N 0
#define comma
#define a1(X)
#define a1c(X)
#define name(X) X##0
#undef a0
#define a0(X) X
#endif
// content starts here
template <
typename RET
a1c(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8),
RET (*F)(a1(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8))>
class name(FunctionWrapper_1_)
{
public:
typedef void myobjectT;
static int Wrapper(lua_State* L)
{
Pack<RET>::convert(L,
F(a1(Unpack<P1>::convert(L, 1))
a2c(Unpack<P2>::convert(L, 2))
a3c(Unpack<P3>::convert(L, 3))
a4c(Unpack<P4>::convert(L, 4))
a5c(Unpack<P5>::convert(L, 5))
a6c(Unpack<P6>::convert(L, 6))
a7c(Unpack<P7>::convert(L, 7))
a8c(Unpack<P8>::convert(L, 8))
));
runAutoRelease();
return 1;
}
static const bool hasmeta = false;
static const bool noindex = true;
};
template <
a1(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
comma
void (*F)(a1(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8))>
class name(FunctionWrapper_0_)
{
public:
typedef void myobjectT;
static int Wrapper(lua_State* L)
{
F(a1(Unpack<P1>::convert(L, 1))
a2c(Unpack<P2>::convert(L, 2))
a3c(Unpack<P3>::convert(L, 3))
a4c(Unpack<P4>::convert(L, 4))
a5c(Unpack<P5>::convert(L, 5))
a6c(Unpack<P6>::convert(L, 6))
a7c(Unpack<P7>::convert(L, 7))
a8c(Unpack<P7>::convert(L, 8))
);
runAutoRelease();
return 0;
}
static const bool hasmeta = false;
static const bool noindex = true;
};
template <
a1(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
comma
int (*F)(lua_State* a1c(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8))>
class name(FunctionWrapper_N_)
{
public:
typedef void myobjectT;
static int Wrapper(lua_State* L)
{
int n = F(L
a1c(Unpack<P1>::convert(L, 1))
a2c(Unpack<P2>::convert(L, 2))
a3c(Unpack<P3>::convert(L, 3))
a4c(Unpack<P4>::convert(L, 4))
a5c(Unpack<P5>::convert(L, 5))
a6c(Unpack<P6>::convert(L, 6))
a7c(Unpack<P7>::convert(L, 7))
a8c(Unpack<P7>::convert(L, 8))
);
runAutoRelease();
return n;
}
static const bool hasmeta = false;
static const bool noindex = true;
};
template <
typename OBJ, typename DEFOBJ, typename RET
a1c(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
,
RET (DEFOBJ::*F)(a1(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8))>
class name(MethodWrapper_1_)
{
public:
typedef OBJ myobjectT;
static int Wrapper(lua_State* L)
{
RET (DEFOBJ::*f)(a1(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8)) = F;
OBJ* obj = Unpack<OBJ*>::convert(L, 1);
Pack<RET>::convert(L,
(obj->*f)(a1(Unpack<P1>::convert(L, 2))
a2c(Unpack<P2>::convert(L, 3))
a3c(Unpack<P3>::convert(L, 4))
a4c(Unpack<P4>::convert(L, 5))
a5c(Unpack<P5>::convert(L, 6))
a6c(Unpack<P6>::convert(L, 7))
a7c(Unpack<P7>::convert(L, 8))
a8c(Unpack<P8>::convert(L, 9))
));
runAutoRelease();
return 1;
}
static const bool hasmeta = true;
static const bool noindex = false;
};
template <
typename OBJ,
typename DEFOBJ
a1c(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
,
void (DEFOBJ::*F)(a1(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8))>
class name(MethodWrapper_0_)
{
public:
typedef OBJ myobjectT;
static int Wrapper(lua_State* L)
{
void (DEFOBJ::*f)(a1(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8)) = F;
OBJ* obj = Unpack<OBJ*>::convert(L, 1);
(obj->*f)(a1(Unpack<P1>::convert(L, 2))
a2c(Unpack<P2>::convert(L, 3))
a3c(Unpack<P3>::convert(L, 4))
a4c(Unpack<P4>::convert(L, 5))
a5c(Unpack<P5>::convert(L, 6))
a6c(Unpack<P6>::convert(L, 7))
a7c(Unpack<P7>::convert(L, 8))
a8c(Unpack<P8>::convert(L, 9))
);
runAutoRelease();
return 0;
}
static const bool hasmeta = true;
static const bool noindex = false;
};
template <
typename OBJ,
typename DEFOBJ
a1c(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
,
int (DEFOBJ::*F)(lua_State* a1c(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8))>
class name(MethodWrapper_N_)
{
public:
typedef OBJ myobjectT;
static int Wrapper(lua_State* L)
{
int (DEFOBJ::*f)(lua_State* a1c(P1)a2c(P2)a3c(P3)a4c(P4)a5c(P5)a6c(P6)a7c(P7)a8c(P8)) = F;
OBJ* obj = Unpack<OBJ*>::convert(L, 1);
int n = (obj->*f)(L
a1c(Unpack<P1>::convert(L, 2))
a2c(Unpack<P2>::convert(L, 3))
a3c(Unpack<P3>::convert(L, 4))
a4c(Unpack<P4>::convert(L, 5))
a5c(Unpack<P5>::convert(L, 6))
a6c(Unpack<P6>::convert(L, 7))
a7c(Unpack<P7>::convert(L, 8))
a8c(Unpack<P8>::convert(L, 9))
);
runAutoRelease();
return n;
}
static const bool hasmeta = true;
static const bool noindex = false;
};
template <
typename OBJ
a1c(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
>
class name(CtorWrapper_)
{
public:
typedef OBJ myobjectT;
static int Wrapper(lua_State* L)
{
Pack<OBJ*>::convert(L,
new OBJ(a1(Unpack<P1>::convert(L, 1))
a2c(Unpack<P2>::convert(L, 2))
a3c(Unpack<P3>::convert(L, 3))
a4c(Unpack<P4>::convert(L, 4))
a5c(Unpack<P5>::convert(L, 5))
a6c(Unpack<P6>::convert(L, 6))
a7c(Unpack<P7>::convert(L, 7))
a8c(Unpack<P8>::convert(L, 8))
));
runAutoRelease();
return 1;
}
static const bool hasmeta = true;
static const bool noindex = true;
};
template <
typename RET
a1c(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
,
typename DEF
>
RET name(Call_1_)(lua_State* L, LuaFunctionBase& f
a1c(P1 p1)a2c(P2 p2)a3c(P3 p3)a4c(P4 p4)a5c(P5 p5)a6c(P6 p6)a7c(P7 p7)a8c(P8 p8))
{
if (f.prepareStack (L)) {
a1(Pack<P1>::convert(L, p1);)
a2(Pack<P2>::convert(L, p2);)
a3(Pack<P3>::convert(L, p3);)
a4(Pack<P4>::convert(L, p4);)
a5(Pack<P5>::convert(L, p5);)
a6(Pack<P6>::convert(L, p6);)
a7(Pack<P7>::convert(L, p7);)
a8(Pack<P8>::convert(L, p8);)
lua_call(L, N + f.addValues, 1);
RET val = Unpack<RET, DEF>::convert(L, -1);
lua_pop(L, 1); // pop the returned value
f.cleanStack(L);
return val;
} else
return getDefault<RET, DEF>(L, -1);
}
template <
typename RET
a1c(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
>
RET name(Call_1_)(lua_State* L, LuaFunctionBase& f
a1c(P1 p1)a2c(P2 p2)a3c(P3 p3)a4c(P4 p4)a5c(P5 p5)a6c(P6 p6)a7c(P7 p7)a8c(P8 p8))
{
return name(Call_1_)<RET a1c(P1) a2c(P2) a3c(P3) a4c(P4) a5c(P5) a6c(P6) a7c(P7) a8c(P8), DefaultInitializer<RET> >(
L, f a1c(p1) a2c(p2) a3c(p3) a4c(p4) a5c(p5) a6c(p6) a7c(p7) a8c(p8)
);
}
a1(template <
a1(typename P1)
a2c(typename P2)
a3c(typename P3)
a4c(typename P4)
a5c(typename P5)
a6c(typename P6)
a7c(typename P7)
a8c(typename P8)
>)
static void
#ifdef __GNUC__
__attribute__((unused))
#endif
name(Call_0_)(lua_State* L, LuaFunctionBase& f
a1c(P1 p1)a2c(P2 p2)a3c(P3 p3)a4c(P4 p4)a5c(P5 p5)a6c(P6 p6)a7c(P7 p7)a8c(P8 p8))
{
if (f.prepareStack(L)) {
a1(Pack<P1>::convert(L, p1);)
a2(Pack<P2>::convert(L, p2);)
a3(Pack<P3>::convert(L, p3);)
a4(Pack<P4>::convert(L, p4);)
a5(Pack<P5>::convert(L, p5);)
a6(Pack<P6>::convert(L, p6);)
a7(Pack<P7>::convert(L, p7);)
a8(Pack<P8>::convert(L, p8);)
lua_call(L, N + f.addValues, 0);
f.cleanStack(L);
}
}
// content end
#if N > 0
#include "LuaWrappers.hh"
#else
#undef N
#undef a0
#undef a1
#undef a1c
#undef a2
#undef a2c
#undef a3
#undef a3c
#undef a4
#undef a4c
#undef a5
#undef a5c
#undef a6
#undef a6c
#undef a7
#undef a7c
#undef a8
#undef a8c
#undef name
#endif