[29482] users/rhwood/MacPorts.Framework
source_changes at macosforge.org
source_changes at macosforge.org
Tue Sep 25 02:53:34 PDT 2007
Revision: 29482
http://trac.macosforge.org/projects/macports/changeset/29482
Author: rhwood at macports.org
Date: 2007-09-25 02:53:33 -0700 (Tue, 25 Sep 2007)
Log Message:
-----------
Add methods for getting Arrays and Dictionaries from Tcl_Lists
Modified Paths:
--------------
users/rhwood/MacPorts.Framework/MPInterpreter.h
users/rhwood/MacPorts.Framework/MPInterpreter.m
Modified: users/rhwood/MacPorts.Framework/MPInterpreter.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPInterpreter.h 2007-09-25 08:13:05 UTC (rev 29481)
+++ users/rhwood/MacPorts.Framework/MPInterpreter.h 2007-09-25 09:53:33 UTC (rev 29482)
@@ -26,6 +26,9 @@
- (NSString *)evaluateArrayAsString:(NSArray *)statement;
- (NSString *)evaluateStringAsString:(NSString *)statement;
+- (NSArray *)arrayFromTclListAsString:(NSString *)list;
+- (NSDictionary *)dictionaryFromTclListAsString:(NSString *)list;
+
- (NSArray *)getVariableAsArray:(NSString *)variable;
- (NSString *)getVariableAsString:(NSString *)variable;
Modified: users/rhwood/MacPorts.Framework/MPInterpreter.m
===================================================================
--- users/rhwood/MacPorts.Framework/MPInterpreter.m 2007-09-25 08:13:05 UTC (rev 29481)
+++ users/rhwood/MacPorts.Framework/MPInterpreter.m 2007-09-25 09:53:33 UTC (rev 29482)
@@ -83,15 +83,13 @@
return [NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)];
}
-- (NSArray *)getVariableAsArray:(NSString *)variable {
+- (NSArray *)arrayFromTclListAsString:(NSString *)list {
NSMutableArray *array;
int tclCount;
int tclResult;
int i;
const char **tclElements;
- NSString *contents;
- contents = [NSString stringWithUTF8String:Tcl_GetVar(_interpreter, [variable UTF8String], TCL_LIST_ELEMENT)];
- tclResult = Tcl_SplitList(_interpreter, [contents UTF8String], &tclCount, &tclElements);
+ tclResult = Tcl_SplitList(_interpreter, [list UTF8String], &tclCount, &tclElements);
if (tclResult == TCL_OK) {
array = [[NSMutableArray alloc] initWithCapacity:tclCount];
for (i = 0; i < tclCount; i++) {
@@ -104,6 +102,22 @@
return [NSArray arrayWithArray:array];
}
+- (NSDictionary *)dictionaryFromTclListAsString:(NSString *)list {
+ NSMutableDictionary *dictionary;
+ NSArray *array;
+ int i;
+ array = [self arrayFromTclListAsString:list];
+ dictionary = [[NSMutableDictionary alloc] initWithCapacity:[array count]];
+ for (i = 0; i < [array count]; i += 2) {
+ [dictionary setObject:[array objectAtIndex:(i + 1)] forKey:[array objectAtIndex:i]];
+ }
+ return [NSDictionary dictionaryWithDictionary:dictionary];
+}
+
+- (NSArray *)getVariableAsArray:(NSString *)variable {
+ return [self arrayFromTclListAsString:[NSString stringWithUTF8String:Tcl_GetVar(_interpreter, [variable UTF8String], TCL_LIST_ELEMENT)]];
+}
+
- (NSString *)getVariableAsString:(NSString *)variable {
return [NSString stringWithUTF8String:Tcl_GetVar(_interpreter, [variable UTF8String], 0)];
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070925/b114e76c/attachment.html
More information about the macports-changes
mailing list