Runtime
Runtime copied to clipboard
Is it possible to create a struct instance by its name?
I'm looking some alternative to NSClassFromString but for structs :)
Unfortunately it cannot as of now
@wickwirew but is it theoretically possible?
Potentially. You need to be able to get the type's metadata record from it's name. I do remember seeing a PR go into the compiler that allowed you to get it from the mangled name a while back. Other than that, as far as I know it's not. Would love to add it if it is though
That will be just awesome if you add it!
Hi @wickwirew. Have you got a chance to add this feature? :)
Sorry but its just not possible. You can create a struct type from it's mangled name, but not just simply the name.
if you can create struct Metadata,so you can create struct instance by the name,this is struct Metadata:
struct StructTypeDescriptor: TypeDescriptor {
var flags: ContextDescriptorFlags
var parent: Int32
var mangledName: RelativePointer<Int32, CChar>
var accessFunctionPtr: RelativePointer<Int32, UnsafeRawPointer>
var fieldDescriptor: RelativePointer<Int32, FieldDescriptor>
var numberOfFields: Int32
var offsetToTheFieldOffsetVector: RelativeVectorPointer<Int32, Int32>
var genericContextHeader: TargetTypeGenericContextDescriptorHeader
}
@wickwirew