aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-10-03 21:27:26 +1300
committerArslaan Pathan <[email protected]>2026-10-03 21:27:26 +1300
commit10655bc37c51645ecdcfa2cd8c059a5e0fb17335 (patch)
tree6ab30353f0ef359d10adc450a6bcaaa1eff0289b
parent7647aa38c770ef443f0158ce9996f6b125b0a93b (diff)
downloadParadox-10655bc37c51645ecdcfa2cd8c059a5e0fb17335.tar.xz
Paradox-10655bc37c51645ecdcfa2cd8c059a5e0fb17335.zip
object introspection and respondsToSelector
-rw-r--r--include/Paradox/Object.h12
-rw-r--r--meson.build2
-rw-r--r--src/Object.m63
3 files changed, 62 insertions, 15 deletions
diff --git a/include/Paradox/Object.h b/include/Paradox/Object.h
index d0b77fd..2889cd9 100644
--- a/include/Paradox/Object.h
+++ b/include/Paradox/Object.h
@@ -7,6 +7,8 @@
@interface PXObject {
void* dummy; // it doesn't work without this so don't touch it
}
+
+/* init and lifecycle */
+ (instancetype)alloc;
+ (instancetype)new;
- (instancetype)retain;
@@ -15,6 +17,16 @@
- (void)release;
- (instancetype)autorelease;
+/* object introspection */
+- (Class)class;
+- (Class)superclass;
+- (const char *)className; // CHANGE TO (PXString *) WHEN IMPLEMENTED
+- (BOOL)isKindOfClass:(Class)class;
+- (BOOL)isMemberOfClass:(Class)class;
+
+/* selector stuff */
+- (BOOL)respondsToSelector:(SEL)selector;
+
#ifdef PARADOX_DEBUG_FEATURES
+ (instancetype)allocDebug;
- (void)healthCheck;
diff --git a/meson.build b/meson.build
index b7c5809..845bd03 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
project('paradox', 'objc', version: '0.0.1', meson_version: '>=1.1.0')
-add_project_arguments('-Wno-objc-root-class', '-Werror', '-pedantic', '-Wall', '-fobjc-runtime=gnustep-2.0', language: 'objc')
+add_project_arguments('-Wno-objc-root-class', '-Werror', '-pedantic', '-Wall', '-fobjc-runtime=gnustep-2.0', language: 'objc') # gnustep-2.0 in this context simply means the libobjc2 runtime (which is made by the GNUstep team), not actually GNUstep. Paradox is an independent framework and has no dependency on GNUstep or any other Objective-C application framework.
if get_option('debug_features')
add_project_arguments('-DPARADOX_DEBUG_FEATURES', language: 'objc')
diff --git a/src/Object.m b/src/Object.m
index de0f343..b9250ff 100644
--- a/src/Object.m
+++ b/src/Object.m
@@ -6,24 +6,12 @@
@implementation PXObject
+/* init and lifecycle */
+
+ (instancetype)alloc {
return class_createInstance(self, 0);
}
-#ifdef PARADOX_DEBUG_FEATURES
-+ (instancetype)allocDebug {
- printf("alloc: self = %p\n", (void*)self);
- printf("alloc: instance size = %zu\n", class_getInstanceSize(self));
- printf("alloc: sizeof(Class) = %zu\n", sizeof(Class));
-
- id object = [self alloc];
-
- printf("alloc: object = %p\n", (void*)object);
-
- return object;
-}
-#endif
-
+ (instancetype) new {
return [[self alloc] init];
}
@@ -48,10 +36,57 @@
object_dispose(self);
}
+/* object introspection */
+- (Class)class {
+ return object_getClass(self);
+}
+
+- (Class)superclass {
+ return object_getSuperclass([self class]);
+}
+
+- (const char *)className {
+ return class_getName([self class]);
+}
+
+- (BOOL)isKindOfClass:(Class)class {
+ Class current = [self class];
+
+ while (current != nil) {
+ if (current == class)
+ return YES;
+
+ current = class_getSuperclass(current);
+ }
+
+ return NO;
+}
+
+- (BOOL)isMemberOfClass:(Class)class {
+ return ([self class] == class);
+}
+
+/* selector stuff */
+- (BOOL)respondsToSelector:(SEL)selector {
+ return object_respondsToSelector([self class], selector);
+}
+
#ifdef PARADOX_DEBUG_FEATURES
- (void)healthCheck {
printf("PXObject health check: %p\n", (void*)self);
}
+
++ (instancetype)allocDebug {
+ printf("alloc: self = %p\n", (void*)self);
+ printf("alloc: instance size = %zu\n", class_getInstanceSize(self));
+ printf("alloc: sizeof(Class) = %zu\n", sizeof(Class));
+
+ id object = [self alloc];
+
+ printf("alloc: object = %p\n", (void*)object);
+
+ return object;
+}
#endif
@end