Implement new function by Vercix · Pull Request #128 · godotjs/javascript · GitHub
Skip to content

Implement new function#128

Closed
Vercix wants to merge 1 commit into
godotjs:masterfrom
Vercix:master
Closed

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

Conversation

@Vercix

@Vercix Vercix commented Jun 21, 2022

Copy link
Copy Markdown

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

@fire

fire commented Apr 23, 2023

Copy link
Copy Markdown
Collaborator

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

Ok to close?

@fire

fire commented Apr 26, 2023

Copy link
Copy Markdown
Collaborator

@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