summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-06-17 20:13:16 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-06-17 20:13:16 +0200
commite10c42925058f0fbaa1a3398ddfa9441b33a4e72 (patch)
treea867abe6cb822e158b33cafd9dbd0980bf24e89f
parentd216a7cbc174a35b93c1e5af66b7bc2e1b0284db (diff)
MLKDynamicContext: Introduce a global fallback context.
-rw-r--r--MLKDynamicContext.h2
-rw-r--r--MLKDynamicContext.m30
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