JSObjectRef CYMakeType(JSContextRef context, const char *type);
JSObjectRef CYMakeType(JSContextRef context, sig::Type *type);
+extern JSClassRef Functor_;
+
struct Type_privateData :
CYData
{
return is;
}
+NSObject *CYMakeBlock(void (*invoke)(), sig::Signature &signature) {
+ BlockLiteral *literal(reinterpret_cast<BlockLiteral *>(malloc(sizeof(BlockLiteral))));
+
+ struct Descriptor {
+ struct {
+ BlockDescriptor1 one_;
+ BlockDescriptor2 two_;
+ BlockDescriptor3 three_;
+ } d_;
+
+ CYPool pool_;
+ };
+
+ Descriptor *descriptor(new Descriptor);
+ memset(&descriptor->d_, 0, sizeof(descriptor->d_));
+
+ literal->isa = objc_getClass("__NSGlobalBlock__");
+ literal->flags = BLOCK_HAS_SIGNATURE | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL;
+ literal->reserved = 0;
+ literal->invoke = reinterpret_cast<void (*)(void *, ...)>(invoke);
+ literal->descriptor = descriptor;
+
+ descriptor->d_.one_.size = sizeof(descriptor->d_);
+ descriptor->d_.three_.signature = sig::Unparse(descriptor->pool_, &signature);
+
+ return reinterpret_cast<NSObject *>(literal);
+}
+
NSObject *CYCastNSObject(apr_pool_t *pool, JSContextRef context, JSObjectRef object) {
if (CYJSValueIsNSObject(context, object)) {
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
return internal->GetValue();
}
+ if (JSValueIsObjectOfClass(context, object, Functor_)) {
+ cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(object)));
+ return CYMakeBlock(internal->GetValue(), internal->signature_);
+ }
+
bool array(CYJSValueIsInstanceOfCachedConstructor(context, object, Array_s));
id value(array ? [CYJSArray alloc] : [CYJSObject alloc]);
return CYPoolRelease(pool, [value initWithJSObject:object inContext:context]);
}
CYExpression *CYObjCBlock::Replace(CYContext &context) {
- return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_), parameters_->TypeSignature(context, type_->Replace(context)));
+ return $N2($V("Functor"), $ CYFunctionExpression(NULL, $ CYFunctionParameter($ CYDeclaration($ CYIdentifier("$cyt")), parameters_->Parameters(context)), statements_), parameters_->TypeSignature(context, $ CYAdd(type_->Replace(context), $ CYString("@"))));
}
CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL)