Skip to content

Implement new function#128

Closed
Vercix wants to merge 1 commit intogodotjs:masterfrom
Vercix:master
Closed

Implement new function#128
Vercix wants to merge 1 commit intogodotjs:masterfrom
Vercix:master

Conversation

@Vercix
Copy link
Copy Markdown

@Vercix Vercix commented Jun 21, 2022

This pull request would implement the new function.
This will create a more convenient API for instantiating JavaScript classes in GDScript.

For example:

var ControllerApp = preload("res://dist/GodotFreApp.jsx")

# Called when the node enters the scene tree for the first time.
func _ready():
	var x = ControllerApp.new(1, null, 'some_other_prop', self)
	add_child(x)

This is related to #107

There is a few things that I am not happy about with this implementation, though.

  • I created a new method for the QuickJS binder class, create_ecma_instance_for_godot_object_args, which is essentially a copy of create_ecma_instance_for_godot except that it accepts args. Which are converted into JSValues and then passed to JS_CallConstructor2. I removed the initialize_properties call in the new function which is used in the original function to set properties registered through godot.register_property. Because they are set to null when instantiating through new(). There probably is a better way of handling this though.
  • There probably should be some error checking to see if the Godot class the JavaScript class inherits from exists in emcascript.cpp.

Looking forward to review and suggestions.

@Geequlim
Copy link
Copy Markdown
Collaborator

I don't think this is a good idea to add statics new methods to godot classes.
It will confuse people who are not familiar with godot that much. Some classes can create instances with new method but some are not in same project.
So it is better to follow the EcmaScript standard.

@fire
Copy link
Copy Markdown
Collaborator

fire commented Apr 23, 2023

I don't think @Geequlim agrees with this design, and there has been no activity.

Ok to close?

@fire
Copy link
Copy Markdown
Collaborator

fire commented Apr 26, 2023

Closing due to lack of support from a maintainer.

Feel free to comment or revise.

@fire fire closed this Apr 26, 2023
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.

4 participants