@@ -171,24 +171,6 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_ptr_overload, SetPtr, 1, 2)
171
171
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_ptr_overload, SetStringPtr, 1 , 2 )
172
172
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_array_overload, SetStringArray, 1 , 2 )
173
173
174
- // These three macros ease the exposing part of DynCall
175
- #define EXPOSE_DC_SET (pyname, cppname ) \
176
- .def(" set_arg_" XSTRINGIFY(pyname), \
177
- &CPointer::SetArg##cppname, \
178
- args (" value" ), \
179
- "Adds a new parameter to the virtual machine." \
180
- )
181
-
182
- #define EXPOSE_DC_CALL (pyname, cppname ) \
183
- .def(" call_" XSTRINGIFY(pyname), \
184
- &CPointer::Call##cppname, \
185
- " Calls the virtual machine." \
186
- )
187
-
188
- #define EXPOSE_DC (pyname, cppname ) \
189
- EXPOSE_DC_SET (pyname, cppname) \
190
- EXPOSE_DC_CALL(pyname, cppname)
191
-
192
174
void export_memtools()
193
175
{
194
176
class_<CPointer>(" Pointer" , init< optional<unsigned long > >())
@@ -251,33 +233,6 @@ void export_memtools()
251
233
)
252
234
)
253
235
254
- // DynCall methods
255
- .def (" reset_vm" ,
256
- &CPointer::ResetVM,
257
- " Resets the virtual machine."
258
- )
259
-
260
- .def (" set_mode" ,
261
- &CPointer::SetMode,
262
- " Sets the calling convention." ,
263
- args (" convention" )
264
- )
265
-
266
- EXPOSE_DC_CALL (void , Void)
267
- EXPOSE_DC (bool , Bool)
268
- EXPOSE_DC (char , Char)
269
- EXPOSE_DC (uchar, UChar)
270
- EXPOSE_DC (short , Short)
271
- EXPOSE_DC (ushort , UShort)
272
- EXPOSE_DC (int , Int)
273
- EXPOSE_DC (uint , UInt)
274
- EXPOSE_DC (long , Long)
275
- EXPOSE_DC (ulong, ULong)
276
- EXPOSE_DC (float , Float)
277
- EXPOSE_DC (double , Double)
278
- EXPOSE_DC (pointer, Pointer)
279
- EXPOSE_DC (string, String)
280
-
281
236
// Other methods
282
237
.def (" get_virtual_func" ,
283
238
&CPointer::GetVirtualFunc,
@@ -497,7 +452,7 @@ void export_callbacks()
497
452
498
453
499
454
// -----------------------------------------------------------------------------
500
- // Exposes wrap/get_address functionality
455
+ // Exposes wrap/get_address/TYPE_SIZES functionality
501
456
// -----------------------------------------------------------------------------
502
457
// Use this macro to add the ability to get the address of an object
503
458
#define GET_ADDRESS (type ) \
@@ -507,30 +462,36 @@ void export_callbacks()
507
462
args (" object" ) \
508
463
);
509
464
510
- // Use this macro if the Python name of the type is different to the C++ name
511
- #define WRAP_ADDRESS0 (type, pyname ) \
512
- .def(XSTRINGIFY(pyname), \
465
+ // Use this macro to add the ability to get the size of an object
466
+ #define ADD_SIZE (type ) \
467
+ scope ().attr(" TYPE_SIZES" )[XSTRINGIFY(type)] = sizeof(type);
468
+
469
+ // Use this macro to add the ability to wrap a pointer using an exposed class
470
+ #define WRAP_POINTER (type ) \
471
+ cls.def(XSTRINGIFY(type), \
513
472
&Wrap::WrapIt<type>, \
514
473
"Wraps the given address.", \
515
474
args(" pointer" ), \
516
475
reference_existing_object_policy() \
517
- ).staticmethod(XSTRINGIFY(pyname))
476
+ ).staticmethod(XSTRINGIFY(type));
518
477
519
- // Use this macro if the Python and C++ name of the type are the same
520
- #define WRAP_ADDRESS1 (type ) \
521
- WRAP_ADDRESS0 (type, type)
478
+ // Use this macro to call the three macros all at once
479
+ #define ADD_ALL (type ) \
480
+ GET_ADDRESS (type) \
481
+ WRAP_POINTER(type) \
482
+ ADD_SIZE(type)
522
483
523
484
void export_get_address()
524
485
{
525
- // get_address()
526
- GET_ADDRESS (Vector)
527
- GET_ADDRESS (QAngle)
528
-
529
- // wrap.<type>()
530
- class_<Wrap>( " wrap " , no_init)
531
-
532
- WRAP_ADDRESS1 (Vector )
533
- WRAP_ADDRESS1 (QAngle )
534
-
535
- ;
486
+ // Don't remove this! It's required for the WRAP_POINTER and ADD_SIZE macro.
487
+ scope (). attr ( " TYPE_SIZES " ) = dict ();
488
+ class_<Wrap> cls = class_<Wrap>( " wrap " , no_init);
489
+
490
+ // Add all classes here...
491
+ // mathlib_c
492
+ ADD_ALL (Vector)
493
+ ADD_ALL (QAngle )
494
+ ADD_ALL (Quaternion )
495
+ ADD_ALL ( cplane_t )
496
+ ADD_ALL (RadianEuler)
536
497
}
0 commit comments