WeaselGames / godot_luaAPI

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

Feature Request:Implement a `LuaAPI.force_stop` method #186

Closed RadiantUwU closed 7 months ago

RadiantUwU commented 8 months ago

Is your feature request related to a problem? Please describe. What if the game just wants to stop everything? It cant just know what was bound or not using signals can it? This is where this method would come into play.

Describe the solution you'd like To efficiently shut down everything, all that would be needed to do is to clear the global table and register table and let the garbage collector do its thing. If there are reference cycles (which would be something very possible), an even better way would be to track what coroutines exist somewhere and then to close them all. If possible, this could be substituted with the lua_closestate to do it all.

Describe alternatives you've considered Having to do it manually from a protected environment. This would mean running some lua code to initialize the API with the debug library active to allow that code to lock everything down and then to run the said code inside the now protected environment. On a shutdown call, it would do exactly as described before. This would also mean that coroutine.create and coroutine.wrap would require modification to track them somewhere.

Trey2k commented 8 months ago

Handling shutdown is on the game. You dont need any lua side code to do this. You just keep track of all states and do whats required to make them stop gracefully. IE using a hook if you need to force the state to stop or otherwise telling the script to stop.

This library helps a lot but state management is out of scope of what I am aiming to do.

EDIT: Also, to properly close the lua state as to clear references all you must do is remove all references to the LuaAPI object.

RadiantUwU commented 8 months ago

Handling shutdown is on the game. You dont need any lua side code to do this. You just keep track of all states and do whats required to make them stop gracefully. IE using a hook if you need to force the state to stop or otherwise telling the script to stop.

This library helps a lot but state management is out of scope of what I am aiming to do.

EDIT: Also, to properly close the lua state as to clear references all you must do is remove all references to the LuaAPI object.

This wont work for when callables are properly implemented as they will have callables hooked up to it and those callables will have a reference.

RadiantUwU commented 8 months ago

Anyways to properly fix this there will be needed a modification to what is gonna be inside the callablecustom, for example when the luaAPI has called force_stop it would then release the reference and return without actually calling it, so that way it is actually detached.

Trey2k commented 8 months ago

This wont work for when callables are properly implemented as they will have callables hooked up to it and those callables will have a reference.

This is inaccurate. It was when the comment was made but I was waiting on changes to be made to the GDExtension side of CallableCustoms that made storing the reference of the object no longer required. So when #180 is merged all we will store is the ObjectID and not the Object its self.

Trey2k commented 8 months ago

You can also utilize the lua garbage collector with the methods we have exposed for that in order to purge references from with the lua state.