]> git.saurik.com Git - cycript.git/commitdiff
Implemented pointer indirect assignment.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 11 Oct 2009 05:12:10 +0000 (05:12 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 11 Oct 2009 05:12:10 +0000 (05:12 +0000)
Library.mm

index f2ba5fc3225fd7a8c5f2bbcd9a88b5d63494cd50..db7a1841e9bd22e65f2454b340a0ed12a97e81ca 100644 (file)
@@ -1663,6 +1663,26 @@ static JSValueRef Pointer_getProperty(JSContextRef context, JSObjectRef object,
     } CYCatch
 }
 
+static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) {
+    CYPool pool;
+    Pointer *internal(reinterpret_cast<Pointer *>(JSObjectGetPrivate(object)));
+    Type_privateData *typical(internal->type_);
+
+    ssize_t index;
+    if (!CYGetIndex(pool, property, index))
+        return NULL;
+
+    ffi_type *ffi(typical->GetFFI());
+
+    uint8_t *base(reinterpret_cast<uint8_t *>(internal->value_));
+    base += ffi->size * index;
+
+    CYTry {
+        CYPoolFFI(NULL, context, &typical->type_, ffi, base, value);
+        return true;
+    } CYCatch
+}
+
 static JSValueRef Struct_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
     CYPool pool;
     Struct_privateData *internal(reinterpret_cast<Struct_privateData *>(JSObjectGetPrivate(object)));
@@ -2132,6 +2152,7 @@ MSInitialize { _pooled
     definition.className = "Pointer";
     definition.staticFunctions = Pointer_staticFunctions;
     definition.getProperty = &Pointer_getProperty;
+    definition.setProperty = &Pointer_setProperty;
     definition.finalize = &CYData::Finalize;
     Pointer_ = JSClassCreate(&definition);