WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
349 stars 27 forks source link

Feature Request:Cross VM object support #185

Open RadiantUwU opened 8 months ago

RadiantUwU commented 8 months ago

The problem is having multiple VMs for mods that load and then be able to completely pass around objects between states, for example threads or functions.

Describe the solution you'd like The solution would be simply making it work between pull_variant and push_variant.

Currently the only issue is LuaCoroutine not working as expected. Other than that, callables/functions will be automatically fixed as expected after the pull request to solve the memory leak #155

Describe alternatives you've considered Creating custom proxy objects to allow this, but it still does not solve the issue #155 with callables.

Additional context This will be used between cross-mod communication, for example between core mod and the other loaded mods, or between a mod and another loaded mod.

Trey2k commented 8 months ago

For the case of threads, we can use a method similar to what ive done for callables and check if the state is different. If it is use lua_xmove. Besides threads, functions will be fixed in #155 as mentioned and any other value being moved by copy is probably expected and valid.

RadiantUwU commented 8 months ago

For the case of threads, we can use a method similar to what ive done for callables and check if the state is different. If it is use lua_xmove. Besides threads, functions will be fixed in #155 as mentioned and any other value being moved by copy is probably expected and valid.

This is a way different case, something that i tackled before, in this scenario, it has a different main thread, meaning different top-level state, meaning they also have different GCs and will not work with lua_xmove

lucidium4 commented 4 months ago

Here a quote regarding sharing objects in lua Source

Yes, you cannot "easily" pass objects between Lua states. You can serialize raw data, but you cannot really pass Lua index references and upvalues and so on across Lua states without doing some serious marshalling. But generally you only have one main Lua state which is shared within your program.

Trey2k commented 4 months ago

Yeah, I don't think there is any way for this to be implemented. Originally I had misunderstood the xmove method. For the case of godot objects they are passed to lua via reference anyways. I have plans to also allow passing godot container types to lua by reference to avoid copying large data sets which I think will mitigate this issue a ton anyways.

I think it is valid to have each mod have a unique state. The drawbacks will just need to be considered.