/[gnustep]/gnustep/dev-libs/StepTalk/Modules/ObjectiveC/NSObject+additions.m
ViewVC logotype

Contents of /gnustep/dev-libs/StepTalk/Modules/ObjectiveC/NSObject+additions.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Fri Oct 3 16:30:05 2003 UTC (20 years, 7 months ago) by stefanu
Branch: MAIN
CVS Tags: StepTalk-0_10_0, StepTalk-0_9_0, StepTalk-0_9_1, StepTalk-0_8_1, StepTalk-0_8_2, HEAD
Changes since 1.2: +2 -1 lines
Added ReadlineTranscript

1 /**
2 NSObject+additions
3
4 Copyright (c) 2002 Free Software Foundation
5
6 Written by: Stefan Urbanek <urbanek@host.sk>
7 Date: 2002 Jun 14
8
9 This file is part of the StepTalk project.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
24
25 */
26
27 #import "NSObject+additions.h"
28
29 #import <objc/objc-api.h>
30
31 #import <Foundation/NSArray.h>
32
33 static NSArray *methods_for_class(Class class)
34 {
35 NSMutableArray *array = [NSMutableArray array];
36 struct objc_method_list *methods;
37 SEL sel;
38 int i;
39
40 if(!class)
41 return nil;
42
43 methods = class->methods;
44
45 while(methods)
46 {
47 for(i = 0; i < methods->method_count; i++)
48 {
49 sel = methods->method_list[i].method_name;
50 [array addObject:NSStringFromSelector(sel)];
51 }
52
53 methods = methods->method_next;
54 }
55
56 return [NSArray arrayWithArray:array];
57 }
58
59 static NSArray *ivars_for_class(Class class)
60 {
61 NSMutableArray *array;
62 struct objc_ivar_list* ivars;
63 const char *cname;
64 int i;
65
66 if(!class)
67 return nil;
68
69 array = [NSMutableArray array];
70
71 ivars = class->ivars;
72
73 if(ivars)
74 {
75 for(i=0;i<ivars->ivar_count;i++)
76 {
77 cname = ivars->ivar_list[i].ivar_name;
78 [array addObject:[NSString stringWithCString:cname]];
79 }
80 }
81
82 return [NSArray arrayWithArray:array];
83 }
84
85 @implementation NSObject(ObjectiveCRuntime)
86 + (NSArray *)instanceMethodNames
87 {
88 return methods_for_class(self);
89 }
90
91 - (NSArray *)methodNames
92 {
93 return [[[self class] instanceMethodNames]
94 sortedArrayUsingSelector:@selector(compare:)];
95 }
96
97 + (NSArray *)methodNames
98 {
99 return methods_for_class(class_get_meta_class(self));
100 }
101
102 + (NSArray *)instanceVariableNames
103 {
104 return ivars_for_class(self);
105 }
106 @end

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26