|
| 1 | +/*! |
| 2 | +@header Nu.h |
| 3 | +The public interface for the Nu programming language. |
| 4 | +Objective-C programs can call Nu scripts by simply including this file, |
| 5 | +which is built into the Nu framework. |
| 6 | +
|
| 7 | +@copyright Copyright (c) 2007 Neon Design Technology, Inc. |
| 8 | +
|
| 9 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +you may not use this file except in compliance with the License. |
| 11 | +You may obtain a copy of the License at |
| 12 | +
|
| 13 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +
|
| 15 | +Unless required by applicable law or agreed to in writing, software |
| 16 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +See the License for the specific language governing permissions and |
| 19 | +limitations under the License. |
| 20 | +*/ |
| 21 | +#import <Foundation/Foundation.h> |
| 22 | + |
| 23 | +@protocol NuParsing |
| 24 | +/*! Parse a string into a list of objects that can be evaluated. */ |
| 25 | +- (id) parse:(NSString *)string; |
| 26 | +/*! Evaluate a parsed code structure in the parser's context. */ |
| 27 | +- (id) eval:(id) code; |
| 28 | +/*! Parse and evaluate a string containing Nu source code. */ |
| 29 | +- (id) parseEval:(NSString *) string; |
| 30 | +/*! Get the value of a name or expression in the parser's context. */ |
| 31 | +- (id) valueForKey:(NSString *)string; |
| 32 | +/*! Set the value of a name in the parser's context. Use this to insert object references into Nu contexts. */ |
| 33 | +- (void) setValue:(id)value forKey:(NSString *)string; |
| 34 | +/*! Call this when you're finished using a parser. */ |
| 35 | +- (void) close; |
| 36 | +@end |
| 37 | + |
| 38 | +/*! |
| 39 | + @class Nu |
| 40 | + @abstract An Objective-C class that provides access to a Nu parser. |
| 41 | + @discussion This class provides a simple interface that allows Objective-C code to run code written in Nu. |
| 42 | + It is intended for use in Objective-C programs that include Nu as a framework. |
| 43 | + */ |
| 44 | +@interface Nu : NSObject |
| 45 | +{ |
| 46 | +} |
| 47 | + |
| 48 | +/*! |
| 49 | +Get a Nu parser. The parser will implement the NuParsing protocol, shown below. |
| 50 | +
|
| 51 | +<div style="margin-left:2em"> |
| 52 | +<code> |
| 53 | +@protocol NuParsing<br/> |
| 54 | +// parse a string containing Nu expressions into a code object.<br/> |
| 55 | +- (id) parse:(NSString *)string;<br/> |
| 56 | +// evaluate a code object in the parser's evaluation context.<br/> |
| 57 | +- (id) eval: (id) code;<br/> |
| 58 | +// Get the value of a name or expression in the parser's context.<br/> |
| 59 | +- (id) valueForKey:(NSString *)string;<br/> |
| 60 | +// Set the value of a name in the parser's context. Use this to insert object references into Nu contexts.<br/> |
| 61 | +- (void) setValue:(id)value forKey:(NSString *)string;<br/> |
| 62 | +// Call this when you're finished using a parser.<br/> |
| 63 | +- (void) close;<br/> |
| 64 | +@end |
| 65 | +</code> |
| 66 | +</div> |
| 67 | +*/ |
| 68 | ++ (id<NuParsing>) parser; |
| 69 | +/*! |
| 70 | +Load a Nu source file from a bundle with the specified identifier. |
| 71 | +Used by bundle (aka framework) initializers. |
| 72 | +*/ |
| 73 | ++ (BOOL) loadNuFile:(NSString *) fileName fromBundleWithIdentifier:(NSString *) bundleIdentifier withContext:(NSMutableDictionary *) context; |
| 74 | +@end |
| 75 | + |
| 76 | +// Helpers for programmatic construction of Nu code. |
| 77 | +// Experimental. They may change or disappear in future releases. |
| 78 | +id _nunull(); |
| 79 | +id _nustring(const char *string); |
| 80 | +id _nusymbol(const char *string); |
| 81 | +id _nunumberd(double d); |
| 82 | +id _nucell(id car, id cdr); |
| 83 | +id _nuregex(const char *pattern, int options); |
0 commit comments