@@ -44,6 +44,7 @@ void export_memtools();
44
44
void export_dyncall ();
45
45
void export_dynamichooks ();
46
46
void export_callbacks ();
47
+ void export_get_address ();
47
48
48
49
DECLARE_SP_MODULE (memory_c)
49
50
{
@@ -52,6 +53,7 @@ DECLARE_SP_MODULE(memory_c)
52
53
export_dyncall ();
53
54
export_dynamichooks ();
54
55
export_callbacks ();
56
+ export_get_address ();
55
57
}
56
58
57
59
// -----------------------------------------------------------------------------
@@ -109,7 +111,7 @@ void export_binaryfile()
109
111
110
112
111
113
// -----------------------------------------------------------------------------
112
- // Exposes CPointer
114
+ // Exposes CPointer and CFunction
113
115
// -----------------------------------------------------------------------------
114
116
#define OVERLOAD_GET_TYPE (name, type ) \
115
117
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (get_##name##_overload, CPointer::Get<type>, 0 , 1 )
@@ -380,8 +382,7 @@ void export_memtools()
380
382
def (" alloc" ,
381
383
Alloc,
382
384
" Allocates a memory block." ,
383
- args (" size" ),
384
- manage_new_object_policy ()
385
+ args (" size" )
385
386
);
386
387
387
388
class_<CFunction, bases<CPointer> >(" Function" , init<unsigned long , Convention_t, char *>())
@@ -481,6 +482,9 @@ void export_dynamichooks()
481
482
;
482
483
}
483
484
485
+ // -----------------------------------------------------------------------------
486
+ // Exposes CCallback
487
+ // -----------------------------------------------------------------------------
484
488
void export_callbacks ()
485
489
{
486
490
class_< CCallback, bases< CFunction > >(" Callback" , init< object, Convention_t, char * >())
@@ -490,3 +494,43 @@ void export_callbacks()
490
494
)
491
495
;
492
496
}
497
+
498
+
499
+ // -----------------------------------------------------------------------------
500
+ // Exposes wrap/get_address functionality
501
+ // -----------------------------------------------------------------------------
502
+ // Use this macro to add the ability to get the address of an object
503
+ #define GET_ADDRESS (type ) \
504
+ def (" get_address" , \
505
+ &GetAddress<type>, \
506
+ " Returns the memory address of the given object." , \
507
+ args (" object" ) \
508
+ );
509
+
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), \
513
+ &Wrap::WrapIt<type>, \
514
+ "Wraps the given address.", \
515
+ args(" pointer" ), \
516
+ reference_existing_object_policy() \
517
+ ).staticmethod(XSTRINGIFY(pyname))
518
+
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)
522
+
523
+ void export_get_address()
524
+ {
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
+ ;
536
+ }
0 commit comments