godotjs / javascript

Javascript binding for godotengine
https://godotjs.github.io/
MIT License
982 stars 82 forks source link

Document how to add a new function in godot/core that is accessible via JS binding #70

Closed Flux159 closed 4 years ago

Flux159 commented 4 years ago

I was just experimenting with adding a new function to godot/core/image.cpp to access through Javascript and thought it would be useful to document for others who needed new C++ methods accessible via Javascript (for perf or other reasons).

I made a gist here: https://gist.github.com/Flux159/b602806d3941e530e87cf969400a7994 with notes, but the basics are as follows for image.cpp:

Then recompile godot w/ the ECMAScript module.

I don't know if there are limitations to functions created this way (do return values need to be specific primitives?) and I don't know if other core apis always have a _bind_methods() function, but it would be helpful to add to the readme, wiki, or some other docs how to do this in a generic way.

Flux159 commented 4 years ago

This is documented in godot's documentation & seems to work the same for Ecmascript, closing out.

https://docs.godotengine.org/en/stable/development/cpp/binding_to_external_libraries.html