1
|
1 /**
|
|
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
|
|
3 * Authors: Jacob Carlborg
|
|
4 * Version: Initial created: Feb 1, 2009
|
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
|
|
6 */
|
|
7 module dstep.objc.runtime;
|
|
8
|
|
9 import mambo.io;
|
|
10
|
|
11 import dstep.internal.String;
|
|
12 import dstep.internal.Types;
|
|
13 import dstep.internal.Version;
|
|
14 import bindings = dstep.objc.bindings;
|
|
15 import dstep.objc.message;
|
|
16 import dstep.objc.objc;
|
|
17
|
|
18 alias objc_method* Method;
|
|
19 alias objc_ivar* Ivar;
|
|
20 alias objc_category* Category;
|
|
21 alias void* objc_property;
|
|
22 alias objc_property* objc_property_t;
|
|
23 alias objc_object Protocol;
|
|
24 alias objc_symtab* Symtab;
|
|
25 alias objc_cache* Cache;
|
|
26
|
|
27 const char _C_ID = '@';
|
|
28 const char _C_CLASS = '#';
|
|
29 const char _C_SEL = ':';
|
|
30 const char _C_CHR = 'c';
|
|
31 const char _C_UCHR = 'C';
|
|
32 const char _C_SHT = 's';
|
|
33 const char _C_USHT = 'S';
|
|
34 const char _C_INT = 'i';
|
|
35 const char _C_UINT = 'I';
|
|
36 const char _C_LNG = 'l';
|
|
37 const char _C_ULNG = 'L';
|
|
38 const char _C_LNG_LNG = 'q';
|
|
39 const char _C_ULNG_LNG = 'Q';
|
|
40 const char _C_FLT = 'f';
|
|
41 const char _C_DBL = 'd';
|
|
42 const char _C_BFLD = 'b';
|
|
43 const char _C_BOOL = 'B';
|
|
44 const char _C_VOID = 'v';
|
|
45 const char _C_UNDEF = '?';
|
|
46 const char _C_PTR = '^';
|
|
47 const char _C_CHARPTR = '*';
|
|
48 const char _C_ATOM = '%';
|
|
49 const char _C_ARY_B = '[';
|
|
50 const char _C_ARY_E = ']';
|
|
51 const char _C_UNION_B = '(';
|
|
52 const char _C_UNION_E = ')';
|
|
53 const char _C_STRUCT_B = '{';
|
|
54 const char _C_STRUCT_E = '}';
|
|
55 const char _C_VECTOR = '!';
|
|
56 const char _C_CONST = 'r';
|
|
57
|
|
58 struct objc_class
|
|
59 {
|
|
60 Class isa;
|
|
61 Class super_class;
|
|
62 /*const*/ char* name;
|
|
63 c_long version_;
|
|
64 c_long info;
|
|
65 c_long instance_size;
|
|
66 objc_ivar_list* ivars;
|
|
67 objc_method_list** methodLists;
|
|
68 objc_cache* cache;
|
|
69 objc_protocol_list* protocols;
|
|
70
|
|
71
|
|
72
|
|
73 // D Extensions:
|
|
74
|
|
75 void setFutureClass (string name) ()
|
|
76 {
|
|
77 bindings.objc_setFutureClass(this, name.ptr);
|
|
78 }
|
|
79
|
|
80 string getName ()
|
|
81 {
|
|
82 return fromStringz(bindings.class_getName(this));
|
|
83 }
|
|
84
|
|
85 Ivar getInstanceVariable (string name) ()
|
|
86 {
|
|
87 return bindings.class_getInstanceVariable(this, name.ptr);
|
|
88 }
|
|
89
|
|
90 Ivar getClassVariable (string name) ()
|
|
91 {
|
|
92 return bindings.class_getClassVariable(this, name.ptr);
|
|
93 }
|
|
94
|
|
95 Ivar[] copyIvarList ()
|
|
96 {
|
|
97 uint outCount;
|
|
98
|
|
99 Ivar* list = bindings.class_copyIvarList(this, &outCount);
|
|
100
|
|
101 if (list)
|
|
102 return list[0 .. outCount];
|
|
103
|
|
104 return null;
|
|
105 }
|
|
106
|
|
107 Method[] copyMethodList ()
|
|
108 {
|
|
109 uint outCount;
|
|
110
|
|
111 Method* list = bindings.class_copyMethodList(this, &outCount);
|
|
112
|
|
113 if (list)
|
|
114 return list[0 .. outCount];
|
|
115
|
|
116 return null;
|
|
117 }
|
|
118
|
|
119 Protocol*[] copyProtocolList ()
|
|
120 {
|
|
121 uint outCount;
|
|
122
|
|
123 Protocol** list = bindings.class_copyProtocolList(this, &outCount);
|
|
124
|
|
125 if (list)
|
|
126 return list[0 .. outCount];
|
|
127
|
|
128 return null;
|
|
129 }
|
|
130
|
|
131 string getIvarLayout ()
|
|
132 {
|
|
133 return fromStringz(bindings.class_getIvarLayout(this));
|
|
134 }
|
|
135
|
|
136 string getWeakIvarLayout ()
|
|
137 {
|
|
138 return fromStringz(bindings.class_getWeakIvarLayout(this));
|
|
139 }
|
|
140
|
|
141 Class duplicateClass (string name) (size_t extraBytes)
|
|
142 {
|
|
143 return bindings.objc_duplicateClass(this, name.ptr, extraBytes);
|
|
144 }
|
|
145
|
|
146 bool addMethod (string types) (SEL name, IMP imp)
|
|
147 {
|
|
148 return bindings.class_addMethod(this, name, imp, types.ptr);
|
|
149 }
|
|
150
|
|
151 IMP replaceMethod (string types) (SEL name, IMP imp)
|
|
152 {
|
|
153 return bindings.class_replaceMethod(this, name, imp, types.ptr);
|
|
154 }
|
|
155
|
|
156 bool addIvar (string name, string types) (size_t size, ubyte alignment)
|
|
157 {
|
|
158 return bindings.class_addIvar(this, name.ptr, size, alignment, types.ptr);
|
|
159 }
|
|
160
|
|
161 void setIvarLayout (string layout) ()
|
|
162 {
|
|
163 bindings.class_setIvarLayout(this, layout.ptr);
|
|
164 }
|
|
165
|
|
166 void setWeakIvarLayout (string layout) ()
|
|
167 {
|
|
168 bindings.class_setWeakIvarLayout(this, layout.ptr);
|
|
169 }
|
|
170
|
|
171 objc_property_t* getProperty (string name) ()
|
|
172 {
|
|
173 return bindings.class_getProperty(this, name.ptr);
|
|
174 }
|
|
175
|
|
176 string getImageName ()
|
|
177 {
|
|
178 return fromStringz(bindings.class_getImageName(this));
|
|
179 }
|
|
180
|
|
181 bool isMetaClass ()
|
|
182 {
|
|
183 return bindings.class_isMetaClass(this);
|
|
184 }
|
|
185
|
|
186 Class getSuperclass ()
|
|
187 {
|
|
188 return bindings.class_getSuperclass(this);
|
|
189 }
|
|
190
|
|
191 Class setSuperClass (Class newSuper)
|
|
192 {
|
|
193 return bindings.class_setSuperclass(this, newSuper);
|
|
194 }
|
|
195
|
|
196 int getVersion ()
|
|
197 {
|
|
198 return bindings.class_getVersion(this);
|
|
199 }
|
|
200
|
|
201 void serVersion (int version_)
|
|
202 {
|
|
203 return bindings.class_setVersion(this, version_);
|
|
204 }
|
|
205
|
|
206 size_t getInstanceSize ()
|
|
207 {
|
|
208 return bindings.class_getInstanceSize(this);
|
|
209 }
|
|
210
|
|
211 Method getInstanceMethod (SEL name)
|
|
212 {
|
|
213 return bindings.class_getInstanceMethod(this, name);
|
|
214 }
|
|
215
|
|
216 Method getClassMethod (SEL name)
|
|
217 {
|
|
218 return bindings.class_getClassMethod(this, name);
|
|
219 }
|
|
220
|
|
221 IMP getMethodImplementation (SEL name)
|
|
222 {
|
|
223 return bindings.class_getMethodImplementation(this, name);
|
|
224 }
|
|
225
|
|
226 IMP getMethodImplementation_stret (SEL name)
|
|
227 {
|
|
228 return bindings.class_getMethodImplementation_stret(this, name);
|
|
229 }
|
|
230
|
|
231 bool respondsToSelector (SEL sel)
|
|
232 {
|
|
233 return bindings.class_respondsToSelector(this, sel);
|
|
234 }
|
|
235
|
|
236 bool conformsToProtocol (Protocol* protocol)
|
|
237 {
|
|
238 return bindings.class_conformsToProtocol(this, protocol);
|
|
239 }
|
|
240
|
|
241 void addProtocol (Protocol* protocol)
|
|
242 {
|
|
243 return bindings.class_addProtocol(this, protocol);
|
|
244 }
|
|
245
|
|
246 id createInstanceFromZone (size_t idxIvars, void* z)
|
|
247 {
|
|
248 return bindings.class_createInstanceFromZone(this, idxIvars, z);
|
|
249 }
|
|
250
|
|
251 void addMethods (objc_method_list* methodList)
|
|
252 {
|
|
253 return.class_addMethods(this, methodList);
|
|
254 }
|
|
255
|
|
256 void removeMethods (objc_method_list* methodList)
|
|
257 {
|
|
258 return bindings.class_removeMethods(this, methodList);
|
|
259 }
|
|
260
|
|
261 Class poseAs (Class original)
|
|
262 {
|
|
263 return bindings.class_poseAs(this, original);
|
|
264 }
|
|
265
|
|
266 bool respondsToMethod (SEL sel)
|
|
267 {
|
|
268 return bindings.class_respondsToMethod(this, sel);
|
|
269 }
|
|
270
|
|
271 objc_method_list* class_nextMethodList (void* arg)
|
|
272 {
|
|
273 return bindings.class_nextMethodList(this, arg);
|
|
274 }
|
|
275 }
|
|
276
|
|
277 struct objc_method_description
|
|
278 {
|
|
279 SEL name;
|
|
280 char* types;
|
|
281 }
|
|
282
|
|
283 struct objc_method_description_list
|
|
284 {
|
|
285 int count;
|
|
286 objc_method_description[1] list;
|
|
287 }
|
|
288
|
|
289 struct objc_protocol_list
|
|
290 {
|
|
291 objc_protocol_list* next;
|
|
292 c_long count;
|
|
293 Protocol*[1] list;
|
|
294 }
|
|
295
|
|
296 struct objc_category
|
|
297 {
|
|
298 char* category_name;
|
|
299 char* class_name;
|
|
300 objc_method_list* instance_methods;
|
|
301 objc_method_list* class_methods;
|
|
302 objc_protocol_list* protocols;
|
|
303 }
|
|
304
|
|
305 struct objc_ivar
|
|
306 {
|
|
307 char* ivar_name;
|
|
308 char* ivar_type;
|
|
309 int ivar_offset;
|
|
310
|
|
311 static if (D_LP64)
|
|
312 int space;
|
|
313
|
|
314
|
|
315
|
|
316 // D Extensions:
|
|
317
|
|
318 string getName ()
|
|
319 {
|
|
320 return fromStringz(bindings.ivar_getName(this));
|
|
321 }
|
|
322
|
|
323 string getTypeEncoding ()
|
|
324 {
|
|
325 return fromStringz(bindings.ivar_getTypeEncoding(this));
|
|
326 }
|
|
327
|
|
328 ptrdiff_t getOffset ()
|
|
329 {
|
|
330 return bindings.ivar_getOffset(this);
|
|
331 }
|
|
332 }
|
|
333
|
|
334 struct objc_ivar_list
|
|
335 {
|
|
336 int ivar_count;
|
|
337
|
|
338 static if (D_LP64)
|
|
339 int space;
|
|
340
|
|
341 /* variable length structure */
|
|
342 objc_ivar[1] ivar_list;
|
|
343 }
|
|
344
|
|
345 struct objc_method
|
|
346 {
|
|
347 SEL method_name;
|
|
348 char* method_types;
|
|
349 IMP method_imp;
|
|
350
|
|
351
|
|
352
|
|
353 // D Extensions:
|
|
354
|
|
355 /*uint getArgumentInfo (string[] type) (int arg, int* offset)
|
|
356 {
|
|
357 char*[] arr;
|
|
358 arr.length = type.length;
|
|
359
|
|
360 foreach (i, str ; type)
|
|
361 arr[i] = str.ptr;
|
|
362
|
|
363 return bindings.method_getArgumentInfo(this, arg, arr.ptr, offset);
|
|
364 }*/
|
|
365
|
|
366 string getTypeEncoding ()
|
|
367 {
|
|
368 return fromStringz(bindings.method_getTypeEncoding(this));
|
|
369 }
|
|
370
|
|
371 string copyReturnType ()
|
|
372 {
|
|
373 return fromStringz(bindings.method_copyReturnType(this));
|
|
374 }
|
|
375
|
|
376 string copyArgumentType (uint index)
|
|
377 {
|
|
378 return fromStringz(bindings.method_copyArgumentType(this, index));
|
|
379 }
|
|
380
|
|
381 void getReturnType (string dst, size_t dst_len)
|
|
382 {
|
|
383 bindings.method_getReturnType(this, dst.toStringz(), dst_len);
|
|
384 }
|
|
385
|
|
386 void getArgumentType (uint index, string dst, size_t dst_len)
|
|
387 {
|
|
388 bindings.method_getArgumentType(this, index, dst.toStringz(), dst_len);
|
|
389 }
|
|
390
|
|
391 SEL getName ()
|
|
392 {
|
|
393 return bindings.method_getName(this);
|
|
394 }
|
|
395
|
|
396 IMP getImplementation ()
|
|
397 {
|
|
398 return bindings.method_getImplementation(this);
|
|
399 }
|
|
400
|
|
401 uint getNumberOfArguments ()
|
|
402 {
|
|
403 return bindings.method_getNumberOfArguments(this);
|
|
404 }
|
|
405
|
|
406 objc_method_description* getDescription ()
|
|
407 {
|
|
408 return bindings.method_getDescription(this);
|
|
409 }
|
|
410
|
|
411 IMP setImplementation (IMP imp)
|
|
412 {
|
|
413 return bindings.method_setImplementation(this, imp);
|
|
414 }
|
|
415
|
|
416 void exchangeImplementations (Method m2)
|
|
417 {
|
|
418 bindings.method_exchangeImplementations(this, m2);
|
|
419 }
|
|
420
|
|
421 uint getSizeOfArguments ()
|
|
422 {
|
|
423 return bindings.method_getSizeOfArguments(this);
|
|
424 }
|
|
425 }
|
|
426
|
|
427 struct objc_method_list
|
|
428 {
|
|
429 objc_method_list* obsolete;
|
|
430
|
|
431 int method_count;
|
|
432
|
|
433 static if (D_LP64)
|
|
434 int space;
|
|
435
|
|
436 /* variable length structure */
|
|
437 objc_method method_list[1];
|
|
438 }
|
|
439
|
|
440 struct objc_symtab
|
|
441 {
|
|
442 c_ulong sel_ref_cnt;
|
|
443 SEL* refs;
|
|
444 ushort cls_def_cnt;
|
|
445 ushort cat_def_cnt;
|
|
446 void*[1] defs;
|
|
447 }
|
|
448
|
|
449 struct objc_cache
|
|
450 {
|
|
451 uint mask /* total = mask + 1 */;
|
|
452 uint occupied;
|
|
453 Method[1] buckets;
|
|
454 }
|
|
455
|
|
456 struct objc_module
|
|
457 {
|
|
458 c_ulong version_;
|
|
459 c_ulong size;
|
|
460 char* name;
|
|
461 Symtab symtab;
|
|
462 }
|
|
463
|
|
464 string object_getClassName (id obj)
|
|
465 {
|
|
466 return fromStringz(bindings.object_getClassName(obj));
|
|
467 }
|
|
468
|
|
469 Ivar object_setInstanceVariable (T) (id obj, string name, T value)
|
|
470 {
|
|
471 return bindings.object_setInstanceVariable(obj, name.toStringz(), value);
|
|
472 }
|
|
473
|
|
474 Ivar object_getInstanceVariable (T) (id obj, string name, out T outValue)
|
|
475 {
|
|
476 return bindings.object_getInstanceVariable(obj, name.toStringz(), &outValue);
|
|
477 }
|
|
478
|
|
479 id objc_getClass (string name)
|
|
480 {
|
|
481 return bindings.objc_getClass(name.toStringz());
|
|
482 }
|
|
483
|
|
484 id objc_getMetaClass (string name)
|
|
485 {
|
|
486 return bindings.objc_getMetaClass(name.toStringz());
|
|
487 }
|
|
488
|
|
489 id objc_lookUpClass (string name)
|
|
490 {
|
|
491 return bindings.objc_lookUpClass(name.toStringz());
|
|
492 }
|
|
493
|
|
494 id objc_getRequiredClass (string name)
|
|
495 {
|
|
496 return bindings.objc_getRequiredClass(name.toStringz());
|
|
497 }
|
|
498
|
|
499 Class objc_getFutureClass (string name)
|
|
500 {
|
|
501 return bindings.objc_getFutureClass(name.toStringz());
|
|
502 }
|
|
503
|
|
504 void objc_setFutureClass (Class cls, string name)
|
|
505 {
|
|
506 bindings.objc_setFutureClass(cls, name.toStringz());
|
|
507 }
|
|
508
|
|
509 id objc_getProtocol (string name)
|
|
510 {
|
|
511 return bindings.objc_getProtocol(name.toStringz());
|
|
512 }
|
|
513
|
|
514 Protocol** objc_copyProtocolList (out uint outCount)
|
|
515 {
|
|
516 return bindings.objc_copyProtocolList(&outCount);
|
|
517 }
|
|
518
|
|
519 string class_getName (Class cls)
|
|
520 {
|
|
521 return fromStringz(bindings.class_getName(cls));
|
|
522 }
|
|
523
|
|
524 Ivar class_getInstanceVariable (Class cls, string name)
|
|
525 {
|
|
526 return bindings.class_getInstanceVariable(cls, name.toStringz());
|
|
527 }
|
|
528
|
|
529 Ivar class_getClassVariable (Class cls, string name)
|
|
530 {
|
|
531 return bindings.class_getClassVariable(cls, name.toStringz());
|
|
532 }
|
|
533
|
|
534 Ivar* class_copyIvarList (Class cls, out uint outCount)
|
|
535 {
|
|
536 return bindings.class_copyIvarList(cls, &outCount);
|
|
537 }
|
|
538
|
|
539 Method* class_copyMethodList (Class cls, out uint outCount)
|
|
540 {
|
|
541 return bindings.class_copyMethodList(cls, &outCount);
|
|
542 }
|
|
543
|
|
544 Protocol** class_copyProtocolList (Class cls, out uint outCount)
|
|
545 {
|
|
546 return bindings.class_copyProtocolList(cls, &outCount);
|
|
547 }
|
|
548
|
|
549 objc_property_t* class_getProperty (Class cls, string name)
|
|
550 {
|
|
551 return bindings.class_getProperty(cls, name.toStringz());
|
|
552 }
|
|
553
|
|
554 objc_property_t* class_copyPropertyList (Class cls, out uint outCount)
|
|
555 {
|
|
556 return bindings.class_copyPropertyList(cls, &outCount);
|
|
557 }
|
|
558
|
|
559 string class_getIvarLayout (Class cls)
|
|
560 {
|
|
561 return fromStringz(bindings.class_getIvarLayout(cls));
|
|
562 }
|
|
563
|
|
564 string class_getWeakIvarLayout (Class cls)
|
|
565 {
|
|
566 return fromStringz(bindings.class_getWeakIvarLayout(cls));
|
|
567 }
|
|
568
|
|
569 Class objc_allocateClassPair (Class superclass, string name, size_t extraBytes)
|
|
570 {
|
|
571 return bindings.objc_allocateClassPair(superclass, name.toStringz(), extraBytes);
|
|
572 }
|
|
573
|
|
574 Class objc_duplicateClass (Class original, string name, size_t extraBytes)
|
|
575 {
|
|
576 return bindings.objc_duplicateClass(original, name.toStringz(), extraBytes);
|
|
577 }
|
|
578
|
|
579 bool class_addMethod (Class cls, SEL name, IMP imp, string types)
|
|
580 {
|
|
581 return bindings.class_addMethod(cls, name, imp, types.toStringz());
|
|
582 }
|
|
583
|
|
584 IMP class_replaceMethod (Class cls, SEL name, IMP imp, string types)
|
|
585 {
|
|
586 return bindings.class_replaceMethod(cls, name, imp, types.toStringz());
|
|
587 }
|
|
588
|
|
589 bool class_addIvar (Class cls, string name, size_t size, ubyte alignment, string types)
|
|
590 {
|
|
591 return bindings.class_addIvar(cls, name.toStringz(), size, alignment, types.toStringz());
|
|
592 }
|
|
593
|
|
594 void class_setIvarLayout (Class cls, string layout)
|
|
595 {
|
|
596 bindings.class_setIvarLayout(cls, layout.toStringz());
|
|
597 }
|
|
598
|
|
599 void class_setWeakIvarLayout (Class cls, string layout)
|
|
600 {
|
|
601 bindings.class_setWeakIvarLayout(cls, layout.toStringz());
|
|
602 }
|
|
603
|
|
604 string method_getTypeEncoding (Method m)
|
|
605 {
|
|
606 return fromStringz(bindings.method_getTypeEncoding(m));
|
|
607 }
|
|
608
|
|
609 string method_copyReturnType (Method m)
|
|
610 {
|
|
611 return fromStringz(bindings.method_copyReturnType(m));
|
|
612 }
|
|
613
|
|
614 string method_copyArgumentType (Method m, uint index)
|
|
615 {
|
|
616 return fromStringz(bindings.method_copyArgumentType(m, index));
|
|
617 }
|
|
618
|
|
619 void method_getReturnType (Method m, string dst, size_t dst_len)
|
|
620 {
|
|
621 bindings.method_getReturnType(m, dst.toStringz(), dst_len);
|
|
622 }
|
|
623
|
|
624 void method_getArgumentType (Method m, uint index, string dst, size_t dst_len)
|
|
625 {
|
|
626 bindings.method_getArgumentType(m, index, dst.toStringz(), dst_len);
|
|
627 }
|
|
628
|
|
629 string ivar_getName (Ivar v)
|
|
630 {
|
|
631 return fromStringz(bindings.ivar_getName(v));
|
|
632 }
|
|
633
|
|
634 string ivar_getTypeEncoding (Ivar v)
|
|
635 {
|
|
636 return fromStringz(bindings.ivar_getTypeEncoding(v));
|
|
637 }
|
|
638
|
|
639 string property_getName (objc_property_t* property)
|
|
640 {
|
|
641 return fromStringz(bindings.property_getName(property));
|
|
642 }
|
|
643
|
|
644 string property_getAttributes (objc_property_t* property)
|
|
645 {
|
|
646 return fromStringz(bindings.property_getAttributes(property));
|
|
647 }
|
|
648
|
|
649 string protocol_getName (id p)
|
|
650 {
|
|
651 return fromStringz(bindings.protocol_getName(p));
|
|
652 }
|
|
653
|
|
654 objc_method_description* protocol_copyMethodDescriptionList(id p, bool isRequiredMethod, bool isInstanceMethod, out uint outCount)
|
|
655 {
|
|
656 return bindings.protocol_copyMethodDescriptionList(p, isRequiredMethod, isInstanceMethod, &outCount);
|
|
657 }
|
|
658
|
|
659 objc_property_t* protocol_getProperty (id proto, string name, bool isRequiredProperty, bool isInstanceProperty)
|
|
660 {
|
|
661 return bindings.protocol_getProperty(proto, name.toStringz(), isRequiredProperty, isInstanceProperty);
|
|
662 }
|
|
663
|
|
664 objc_property_t* protocol_copyPropertyList (id proto, out uint outCount)
|
|
665 {
|
|
666 return bindings.protocol_copyPropertyList(proto, &outCount);
|
|
667 }
|
|
668
|
|
669 Protocol** protocol_copyProtocolList (id proto, out uint outCount)
|
|
670 {
|
|
671 return bindings.protocol_copyProtocolList(proto, &outCount);
|
|
672 }
|
|
673
|
|
674 static string[] objc_copyImageNames (out uint outCount)
|
|
675 {
|
|
676 string[] ret;
|
|
677
|
|
678 char** result = bindings.objc_copyImageNames(&outCount);
|
|
679 ret.length = outCount;
|
|
680
|
|
681 for (size_t i = 0; i < outCount; i++)
|
|
682 ret[i] = fromStringz(result[i]);
|
|
683
|
|
684 return ret;
|
|
685 }
|
|
686
|
|
687 string class_getImageName (Class cls)
|
|
688 {
|
|
689 return fromStringz(bindings.class_getImageName(cls));
|
|
690 }
|
|
691
|
|
692 string[] objc_copyClassNamesForImage (string image, out uint outCount)
|
|
693 {
|
|
694 string[] ret;
|
|
695
|
|
696 char** result = bindings.objc_copyClassNamesForImage(image.toStringz(), &outCount);
|
|
697 ret.length = outCount;
|
|
698
|
|
699 for (size_t i = 0; i < outCount; i++)
|
|
700 ret[i] = fromStringz(result[i]);
|
|
701
|
|
702 return ret;
|
|
703 }
|
|
704
|
|
705 string sel_getName (SEL sel)
|
|
706 {
|
|
707 return fromStringz(bindings.sel_getName(sel));
|
|
708 }
|
|
709
|
|
710 SEL sel_getUid (string str)
|
|
711 {
|
|
712 return bindings.sel_getUid(str.toStringz());
|
|
713 }
|
|
714
|
|
715 SEL sel_registerName (string str)
|
|
716 {
|
|
717 return bindings.sel_registerName(str.toStringz());
|
|
718 }
|
|
719
|
|
720 uint method_getArgumentInfo (objc_method* m, int arg, string[] type, int* offset)
|
|
721 {
|
|
722 char*[] arr;
|
|
723 arr.length = type.length;
|
|
724
|
|
725 foreach (i, str ; type)
|
|
726 arr[i] = str.toStringz();
|
|
727
|
|
728 return bindings.method_getArgumentInfo(m, arg, arr.ptr, offset);
|
|
729 }
|
|
730
|
|
731 Class objc_getOrigClass (string name)
|
|
732 {
|
|
733 return bindings.objc_getOrigClass(name.toStringz());
|
|
734 }
|
|
735
|
|
736 alias bindings.object_copy object_copy;
|
|
737 alias bindings.object_dispose object_dispose;
|
|
738 alias bindings.object_getClass object_getClass;
|
|
739 alias bindings.object_setClass object_setClass;
|
|
740 alias bindings.object_getIndexedIvars object_getIndexedIvars;
|
|
741 alias bindings.object_getIvar object_getIvar;
|
|
742 alias bindings.object_setIvar object_setIvar;
|
|
743 alias bindings.objc_getClassList objc_getClassList;
|
|
744 alias bindings.class_isMetaClass class_isMetaClass;
|
|
745 alias bindings.class_getSuperclass class_getSuperclass;
|
|
746 alias bindings.class_setSuperclass class_setSuperclass;
|
|
747 alias bindings.class_getVersion class_getVersion;
|
|
748 alias bindings.class_setVersion class_setVersion;
|
|
749 alias bindings.class_getInstanceSize class_getInstanceSize;
|
|
750 alias bindings.class_getInstanceMethod class_getInstanceMethod;
|
|
751 alias bindings.class_getClassMethod class_getClassMethod;
|
|
752 alias bindings.class_getMethodImplementation class_getMethodImplementation;
|
|
753 alias bindings.class_getMethodImplementation_stret class_getMethodImplementation_stret;
|
|
754 alias bindings.class_respondsToSelector class_respondsToSelector;
|
|
755 alias bindings.class_conformsToProtocol class_conformsToProtocol;
|
|
756 alias bindings.class_createInstance class_createInstance;
|
|
757 alias bindings.objc_registerClassPair objc_registerClassPair;
|
|
758 alias bindings.objc_disposeClassPair objc_disposeClassPair;
|
|
759 alias bindings.class_addProtocol class_addProtocol;
|
|
760 alias bindings.method_getName method_getName;
|
|
761 alias bindings.method_getImplementation method_getImplementation;
|
|
762 alias bindings.method_getNumberOfArguments method_getNumberOfArguments;
|
|
763 alias bindings.method_getDescription method_getDescription;
|
|
764 alias bindings.method_setImplementation method_setImplementation;
|
|
765 alias bindings.method_exchangeImplementations method_exchangeImplementations;
|
|
766 alias bindings.ivar_getOffset ivar_getOffset;
|
|
767 alias bindings.protocol_conformsToProtocol protocol_conformsToProtocol;
|
|
768 alias bindings.protocol_isEqual protocol_isEqual;
|
|
769 alias bindings.protocol_getMethodDescription protocol_getMethodDescription;
|
|
770 alias bindings.sel_isEqual sel_isEqual;
|
|
771 alias bindings.objc_enumerationMutation objc_enumerationMutation;
|
|
772 alias bindings.objc_setForwardHandler objc_setForwardHandler;
|
|
773 alias bindings.sel_isMapped sel_isMapped;
|
|
774 alias bindings.object_copyFromZone object_copyFromZone;
|
|
775 alias bindings.object_realloc object_realloc;
|
|
776 alias bindings.object_reallocFromZone object_reallocFromZone;
|
|
777 alias bindings.objc_getClasses objc_getClasses;
|
|
778 alias bindings.objc_addClass objc_addClass;
|
|
779 alias bindings.objc_setMultithreaded objc_setMultithreaded;
|
|
780 alias bindings.class_createInstanceFromZone class_createInstanceFromZone;
|
|
781 alias bindings.class_addMethods class_addMethods;
|
|
782 alias bindings.class_removeMethods class_removeMethods;
|
|
783 alias bindings.class_poseAs class_poseAs;
|
|
784 alias bindings.method_getSizeOfArguments method_getSizeOfArguments;
|
|
785 alias bindings.class_respondsToMethod class_respondsToMethod;
|
|
786 alias bindings.class_lookupMethod class_lookupMethod;
|
|
787 alias bindings.class_nextMethodList class_nextMethodList;
|
|
788
|
|
789
|
|
790
|
|
791
|
|
792
|
|
793
|
|
794
|
|
795
|
|
796 // D Extensions:
|
|
797
|
|
798 struct objc
|
|
799 {
|
|
800 static string[] copyImageNames (out uint outCount)
|
|
801 {
|
|
802 string[] ret;
|
|
803
|
|
804 char** result = bindings.objc_copyImageNames(&outCount);
|
|
805 ret.length = outCount;
|
|
806
|
|
807 for (size_t i = 0; i < outCount; i++)
|
|
808 ret[i] = fromStringz(result[i]);
|
|
809
|
|
810 return ret;
|
|
811 }
|
|
812
|
|
813 alias bindings.objc_enumerationMutation objc_enumerationMutation;
|
|
814 alias bindings.objc_setForwardHandler objc_setForwardHandler;
|
|
815 alias bindings.objc_setMultithreaded objc_setMultithreaded;
|
|
816
|
|
817 static id getClass (string name) ()
|
|
818 {
|
|
819 return bindings.objc_getClass(name.ptr);
|
|
820 }
|
|
821
|
|
822 static id getMetaClass (string name) ()
|
|
823 {
|
|
824 return bindings.objc_getMetaClass(name.ptr);
|
|
825 }
|
|
826
|
|
827 static id lookUpClass (string name) ()
|
|
828 {
|
|
829 return bindings.objc_lookUpClass(name.ptr);
|
|
830 }
|
|
831
|
|
832 static id getRequiredClass (string name) ()
|
|
833 {
|
|
834 return bindings.objc_getRequiredClass(name.ptr);
|
|
835 }
|
|
836
|
|
837 static Class getFutureClass (string name) ()
|
|
838 {
|
|
839 return bindings.objc_getFutureClass(name.ptr);
|
|
840 }
|
|
841
|
|
842 static string[] objc_copyClassNamesForImage (string image) (out uint outCount)
|
|
843 {
|
|
844 string[] ret;
|
|
845
|
|
846 char** result = bindings.objc_copyClassNamesForImage(image.ptr, &outCount);
|
|
847 ret.length = outCount;
|
|
848
|
|
849 for (size_t i = 0; i < outCount; i++)
|
|
850 ret[i] = fromStringz(result[i]);
|
|
851
|
|
852 return ret;
|
|
853 }
|
|
854
|
|
855 static Class objc_getOrigClass (string name) ()
|
|
856 {
|
|
857 return bindings.objc_getOrigClass(name.ptr);
|
|
858 }
|
|
859
|
|
860 static Class allocateClassPair (string name) (Class superclass, size_t extraBytes)
|
|
861 {
|
|
862 return bindings.objc_allocateClassPair(superclass, name.ptr, extraBytes);
|
|
863 }
|
|
864
|
|
865 alias bindings.objc_registerClassPair registerClassPair;
|
|
866 alias bindings.objc_disposeClassPair disposeClassPair;
|
|
867 alias bindings.objc_getClasses getClasses;
|
|
868 alias bindings.objc_addClass addClass;
|
|
869 alias bindings.class_createInstance createInstance;
|
|
870 }
|
|
871
|
|
872 struct property
|
|
873 {
|
|
874 static string property_getName (objc_property_t* property)
|
|
875 {
|
|
876 return fromStringz(bindings.property_getName(property));
|
|
877 }
|
|
878
|
|
879 static string property_getAttributes (objc_property_t* property)
|
|
880 {
|
|
881 return fromStringz(bindings.property_getAttributes(property));
|
|
882 }
|
|
883 }
|
|
884
|
|
885 struct sel
|
|
886 {
|
|
887 static SEL getUid (string str) ()
|
|
888 {
|
|
889 return bindings.sel_getUid(str.ptr);
|
|
890 }
|
|
891
|
|
892 static SEL registerName (string str) ()
|
|
893 {
|
|
894 return bindings.sel_registerName(str.ptr);
|
|
895 }
|
|
896 } |