-
Notifications
You must be signed in to change notification settings - Fork 116
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
LuaUserDataType
shouldn't require a static lifetime
#20
Comments
It needs a static lifetime for TypeId, right? Edit: I guess it no longer does now that RFC #1849 has landed. I know that practically the lifetime only needs to outlive Lua itself, but I know there are lots of dragons around TypeId and lifetimes other than static, and I might be unqualified to say whether doing this would actually be safe. I feel like it wouldn't be? It's morally equivalent to |
Oh, you're right, good catch. Well, since the RFC isn't yet implemented I guess this will stay a wishlist issue at best, at least for the time being. |
I think that this would also run straight into the same issues as #33. I'm a little gun-shy now about making any of the lifetimes of the transmuted types anything but 'static, so unless we come up with a general strategy to deal with that, if it even exists, we probably shouldn't do this. |
Agreed, closing for now. |
Hello, I recognise the obvious lifetime issue here which is that the lua script shouldn't be able to hang on to the user data after the references expire, but I thought this was sort of what It seems to me that I've thought about some other ways to fix this which is to still produce a |
@t-veor I recently tried again to lift this limitation, and though I no longer think it's impossible, I think it would require an entirely parallel userdata API. Let me explain in more detail... The problem with non-'static But, you might say, why is this restriction able to be lifted for functions via HOWEVER, one could imagine a
So, this is sort of possible but it's a pretty involved change and the best version I can imagine still increases the API surface area quite a lot for a very small amount of gain. But, here's some good news: You can probably already do what you want to do by encoding everything as functions rather than methods on a UserData, it's just much more inconvenient. The reason I know this is that I've actually had to deal with a very similar problem making a scripting API to "query" an ECS-like store, which required locking components and lots of non-'static types, and since I couldn't get non-'static So, the next question is, is it worth it to make a parallel API for I'll keep thinking about how to design a reasonable API and if I come up with one I'll revisit this. |
It's sufficient if the userdata outlives the Lua state. That way it can store references to other Lua objects or the main Lua state, which makes userdata more flexible.
The text was updated successfully, but these errors were encountered: