Skip to content

Bindable CXX lambdas as methods in classes - #1952

Closed
YakoYakoYokuYoku wants to merge 1 commit into
godotengine:masterfrom
YakoYakoYokuYoku:std-function-method-binding
Closed

Bindable CXX lambdas as methods in classes#1952
YakoYakoYokuYoku wants to merge 1 commit into
godotengine:masterfrom
YakoYakoYokuYoku:std-function-method-binding

Conversation

@YakoYakoYokuYoku

Copy link
Copy Markdown

This PR allows API users to bind lambdas as member methods in classes for the bindings, much like Python language C++ bindings such as pybind11. This is a draft implementation of this godotengine/godot-proposals#14485 proposal.

Sample usage.

void Sample::_bind_methods() {
  ClassDB::bind_method(godot::D_METHOD("get_test"), [](const Sample &s) { return s.test; });
  ClassDB::bind_method(godot::D_METHOD("set_test"), [](Sample &s, const String &test) { s.test = test; });
}

See godotengine/godot#117541 for the engine implementation counterpart.

@YakoYakoYokuYoku
YakoYakoYokuYoku force-pushed the std-function-method-binding branch from 6f0d0a6 to 040507c Compare March 21, 2026 15:14
Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
@YakoYakoYokuYoku
YakoYakoYokuYoku force-pushed the std-function-method-binding branch from 040507c to d22f9dc Compare July 25, 2026 13:12
@dsnopek

dsnopek commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Personally, I don't think this is something we should merge into godot-cpp itself. One of godot-cpp's pillars is that's API compatible with Godot, and while we don't achieve that 100%, we shouldn't add new things that are incompatible.

This could be provided as a third-party header-only library for folks who want this convenience and don't need module compatibility.

@YakoYakoYokuYoku

Copy link
Copy Markdown
Author

Could you wait for a sec so that I can confirm that this is doable outside the bindings? Just to put it to rest properly.

@YakoYakoYokuYoku

Copy link
Copy Markdown
Author

I've confirmed that I could do this with an external library, I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants