Question - How to get a callable without executing it?
Heys guys, I was trying a lot of sandboxes for godot to make a modding API for a project but I hit some roadblocks in the way.
At the moment, I am trying to achieve the following:
1 - Godot registry a "mod" global table, that modders append callbacks so the engine run it back, something along the lines of Love2D coding style 2 - The engine gets those callbacks and process them whenever its needed, so I must not use do_string/do_file so its not processed at load time
But it seems that I can't get a function from a global table, or I missed something in the docs (I know that the new docs are on the way thanks to #66) cause its hard to follow just by reading the examples and messing around with the classes
But here is where I am stuck for now, I will be getting some sleep, try to refresh the mind in the meantime
Error:
Attempt to call function 'null::invoke (Callable)' on a null instance.
Edit: Sorry for the comments on the code, as I mentioned I need to do a lot of fiddling around to understand while the docs (xml) aren't that easy to access
Hey @Visnicio, thanks for the question. First of all, I'd say questions are better placed in the Discussions tab, since it's not necessarily an Issue (but it's fine, don't worry, just saying).
Ok, I think I know what's your problem. The thing is that Callables don't store a strong reference to the target object. Even though the function exists in Lua, its Godot counterpart, the LuaFunction RefCounted object, is deleted right after _lua_mods_ready_callback end. The Callable isn't enough to make a RefCounted object live, so you need to keep a strong reference of it somewhere (for example your ready_callbacks array could store LuaFunctions instead of Callables). The Callable's object isn't null when you create it (you could print mod_ready_callback right after creation to check), but the object is invalidated afterwards (thus giving a null when you try to call it).