Closed vitawrap closed 1 year ago
So the colon operator is equivalent to calling obj.method(obj)
, if you would like to support colon methods you can always have your methods expect arg1 to be a self reference. Because of the way we handle things in the back end we always have a reference of the object in question when calling a method so its not strictly needed like it would be with some other familiar lua API implementations.
Since
lua_funcs
doesn't seem to solve this issue, the only way to use methods now is to expose them as Callable fields.
Im not quite sure what you mean with this. lua_funcs was an old method that existed for a short time during the 2.0 alpha. But has since been replaced by lua_fields. See the wiki entry on working with objects here
Keep in mind there has been some discussing in discord regarding the entire permission system, it will likely be changing in favor of a object config approach so that block list, metamethods and maybe some other things will be reusable between object types.
I just saw we have some outdated info in the expose_constructor wiki regarding lua_funcs, this will be fixed shortly. Apologies for the confusion.
Edit: Fixed with https://github.com/WeaselGames/godot_luaAPI_docs/commit/50abe9c78945d8f5342f7b804ab809601dda15ac
So the colon operator is equivalent to calling
obj.method(obj)
, if you would like to support colon methods you can always have your methods expect arg1 to be a self reference. Because of the way we handle things in the back end we always have a reference of the object in question when calling a method so its not strictly needed like it would be with some other familiar lua API implementations.
Thanks, I managed to replicate the colon behavior with fields and the arg1 trick.
Is your feature request related to a problem? Please describe. Since
lua_funcs
doesn't seem to solve this issue, the only way to use methods now is to expose them as Callable fields. The issue is that the code pushes a new method for every construction, with the source object as an upvalue. This creates two issues:lua_funcs
but the example shows that the same issue applies there anyway.Describe the solution you'd like Colon syntax should be the default for method calls
Additional context
should instead be