From 491a0ae5b62ce235253b9837d04075160f60fede Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Sat, 3 Oct 2026 22:56:12 +1300 Subject: add more introspection stuff (and half-written Introspection test) --- include/Paradox/Object.h | 3 +++ src/Object.m | 12 ++++++++++++ tests/Introspection.m | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 tests/Introspection.m diff --git a/include/Paradox/Object.h b/include/Paradox/Object.h index 2889cd9..21b20ac 100644 --- a/include/Paradox/Object.h +++ b/include/Paradox/Object.h @@ -20,6 +20,9 @@ /* object introspection */ - (Class)class; - (Class)superclass; ++ (Class)class; ++ (Class)superclass; ++ (const char *)className; // CHANGE TO (PXString *) WHEN IMPLEMENTED - (const char *)className; // CHANGE TO (PXString *) WHEN IMPLEMENTED - (BOOL)isKindOfClass:(Class)class; - (BOOL)isMemberOfClass:(Class)class; diff --git a/src/Object.m b/src/Object.m index 97b8997..2475be3 100644 --- a/src/Object.m +++ b/src/Object.m @@ -45,6 +45,18 @@ return class_getSuperclass([self class]); } ++ (Class)class { + return self; +} + ++ (Class)superclass { + return class_getSuperclass(self); +} + ++ (const char *)className { + return class_getName(self); +} + - (const char *)className { return class_getName([self class]); } diff --git a/tests/Introspection.m b/tests/Introspection.m new file mode 100644 index 0000000..d54cc0f --- /dev/null +++ b/tests/Introspection.m @@ -0,0 +1,23 @@ +#include +#include + +@interface MyClass : PXObject +- (void)sayHello; +@end + +@implementation MyClass + +- (void)sayHello { + printf("Hello!"); +} + +@end + +int main(void) { + printf("Object introspection test\n"); + MyClass *instance = [MyClass new]; + printf("class = %s\n", class_getName([instance class])); + printf("superclass = %s\n", class_getName([instance superclass])); + printf("className = %s\n", [instance className]); + printf("isMemberOfClass:MyClass = %s\n", [object isMemberOfClass:[MyClass class]]); +} -- cgit v1.2.3