From e10c42925058f0fbaa1a3398ddfa9441b33a4e72 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 17 Jun 2008 20:13:16 +0200 Subject: MLKDynamicContext: Introduce a global fallback context. --- MLKDynamicContext.m | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'MLKDynamicContext.m') diff --git a/MLKDynamicContext.m b/MLKDynamicContext.m index 5b44db7..f5042aa 100644 --- a/MLKDynamicContext.m +++ b/MLKDynamicContext.m @@ -35,7 +35,24 @@ : (id) (parent ? (id) RETAIN (parent_member) : nil)); +static MLKDynamicContext *global_context; + + @implementation MLKDynamicContext ++(void) initialize +{ + NSMutableDictionary *vars = [NSMutableDictionary dictionary]; + + // FIXME: Initialise stuff. + + global_context = [[self alloc] initWithParent:nil + variables:vars + handlers:nil + restarts:nil + catchTags:nil + activeHandlerEnvironment:nil]; +} + -(MLKDynamicContext *) initWithParent:(MLKDynamicContext *)aContext variables:(NSDictionary *)vars handlers:(NSDictionary *)handlers @@ -62,14 +79,19 @@ -(MLKDynamicContext *) pushContext { - return [[[NSThread currentThread] threadDictionary] - objectForKey:@"MLKDynamicContext"]; + [[[NSThread currentThread] threadDictionary] setObject:self + forKey:@"MLKDynamicContext"]; + return self; } +(MLKDynamicContext *) currentContext { - return [[[NSThread currentThread] threadDictionary] - objectForKey:@"MLKDynamicContext"]; + MLKDynamicContext *context = [[[NSThread currentThread] threadDictionary] + objectForKey:@"MLKDynamicContext"]; + if (context) + return context; + else + return global_context; } +(MLKDynamicContext *) popContext -- cgit v1.2.3