Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to create a struct instance by its name? #34

Open
arturdev opened this issue Feb 11, 2019 · 7 comments
Open

Is it possible to create a struct instance by its name? #34

arturdev opened this issue Feb 11, 2019 · 7 comments

Comments

@arturdev
Copy link
Contributor

I'm looking some alternative to NSClassFromString but for structs :)

@wickwirew
Copy link
Owner

wickwirew commented Feb 12, 2019

Unfortunately it cannot as of now

@arturdev
Copy link
Contributor Author

@wickwirew but is it theoretically possible?

@wickwirew
Copy link
Owner

wickwirew commented Feb 12, 2019

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

@arturdev
Copy link
Contributor Author

That will be just awesome if you add it!

@arturdev
Copy link
Contributor Author

Hi @wickwirew. Have you got a chance to add this feature? :)

@wickwirew
Copy link
Owner

Sorry but its just not possible. You can create a struct type from it's mangled name, but not just simply the name.

@jezzmemo
Copy link

jezzmemo commented Jun 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants