diff options
-rw-r--r-- | MLKDynamicContext.h | 2 | ||||
-rw-r--r-- | MLKDynamicContext.m | 30 |
2 files changed, 28 insertions, 4 deletions
diff --git a/MLKDynamicContext.h b/MLKDynamicContext.h index 78c6e82..0fbd5d4 100644 --- a/MLKDynamicContext.h +++ b/MLKDynamicContext.h @@ -30,6 +30,8 @@ MLKDynamicContext *_parent; } ++(void) initialize; + -(MLKDynamicContext *) initWithParent:(MLKDynamicContext *)aContext variables:(NSDictionary *)vars handlers:(NSDictionary *)handlers 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 |