[Extending] Obtaining instance ivar values by key? #398
-
Hey, I'm writing a Swift package for Gravity and I'm having trouble figuring out how to get ivar values by key from an Instance. I see this commented out [Edit] this was for a debug feature, the ivar names are stored in htable. gravity/src/shared/gravity_value.h Line 382 in a135732 and I see this function to set values, but the key argument doesn't appear to be used for anything. gravity/src/shared/gravity_value.c Line 211 in f9e95a4 Is it possible to retrieve an ivar value by it's key, or only by index? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
To get an existing instance value:
[Edit] the closure is for getter and setters which will need to be handled separately in addition to the stored retrieval above. |
Beta Was this translation helpful? Give feedback.
-
This seems to be the basic approach to assign a new stored ivar to a class. let index = gravity_class_add_ivar(gravityClass, name)
let function = gravity_function_new_special(gravity.vm, nil, UInt16(index), nil, nil)
let closure = gravity_closure_new(gravity.vm, function)
gravity_class_bind(gravityClass, name, gravity_value_from_object(closure)) I'm still having an issue where the closure.f pointer gets corrupted or nulled at some point though. |
Beta Was this translation helpful? Give feedback.
-
Hello @STREGAsGate, can you please describe me what are you trying to do? |
Beta Was this translation helpful? Give feedback.
-
Hello @STREGAsGate, good to know that you fixed the issue. Please take a look at the Gravity <-> ObjC bridge, I think it contains a lot of valuable code to you: |
Beta Was this translation helpful? Give feedback.
Hello @STREGAsGate, can you please describe me what are you trying to do?