gilzoide / godot-lua-pluginscript

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI
https://gilzoide.github.io/godot-lua-pluginscript/topics/README.md.html
MIT License
308 stars 21 forks source link

Scripts not reloading in editor #23

Open bram-dingelstad opened 2 years ago

bram-dingelstad commented 2 years ago

Technically it makes a lot more sense to make this an issue in the Godot repo, but thought it'd be worth tracking here as well.

I found this issue as part of the Known Limitations while I was working on #22. I also wonder what the .gdnlib properties called load_once and reloadable have to do with this.

I figured out that the native GDScript solution has a method called reload that we just need to implement in the PluginScript class of the Godot repo (together with some additions to the language descriptors).

Once we have that we just need to make some functions in our language_gdnative.c and we're set!

gilzoide commented 2 years ago

I also wonder what the .gdnlib properties called load_once and reloadable have to do with this.

These are regarding the GDNative library loading/reloading and doesn't affect the PluginScript language. load_once is a flag for the engine to load the shared library only once, regardless of how many scripts reference it. reloadable marks that the GDNative Library can be recompiled and reloaded without restarting the editor. This is marked as false for Lua PluginScript because it is a singleton library and, as by the docs, singleton libraries cannot be reloadable.

I think what is missing for the editor to reload existing scripts reload_all_scripts / reload_tool_script, but I'm not really sure. Maybe there is something the plugin could do to reload stuff, but I haven't searched too much.

bram-dingelstad commented 2 years ago

From what I've seen the reload_all_scripts and reload_tool_script only seem to be relevant in a DEBUG context.

I'm not sure if that's a distro flag that makes it into production versions of Godot. It seems to be a shorthand for debugging purposes that just calls reload on all those script instances.

gilzoide commented 2 years ago

Script reloading is supported both in the editor build (which cannot be release builds and have DEBUG_ENABLED) and debug builds, so that the remote debugger can reload them. I guess this is what is called in editor to reload everything, but I'm still not 100% sure.