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

Allow access to UserData content across the FFI boundary for compact (#[repr(C)]) structures #309

Open
limads opened this issue Aug 15, 2023 · 0 comments

Comments

@limads
Copy link

limads commented Aug 15, 2023

It would be useful to allow access to UserData across different dynamic library modules for structs that are guaranteed to have the same size and alignment. The bytemuck crate exports a few traits that can be implemented using declarative macros in a safe interface that could be used for that purpose.

mlua could export something like:

impl AnyUserData {
    pub fn from_bytes<T : bytemuck::AnyBitPattern>(&self) -> Result<&T,mlua::Error> { ... } 
}

If dependence on bytemuck is undesirable, perhaps AnyUserData could export access to the raw byte slice, done after a few runtime checks (see here an implementation), in which case the user would be responsible for the explicit cast:

impl AnyUserData {
    pub fn as_bytes<T : Sized>(&self) -> Result<&[u8],mlua::Error> { ... } 
}

I don't know how viable this is, however, since mlua would need to keep some information at runtime about the size and alignment of any registered types, and I don't know if this is the case.

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

1 participant