Is it possible to interop with GDScript and JS/TS? #85
Answered
by
nmerget
KameiKojirou
asked this question in
Q&A
-
My apologies if I missed it. Can Godot-js interop GDScript with JS/TS for extending scripts? I really like the ergonomics of using GDScript for most of the game logic, I'm primarily interested in extending it with Node. Is something like this possible in GodotJS? Also is there any limitations on mobile? Grow-GD Exampleextends Node
@onready var go = GoUtils.new()
@onready var number_one = $HBoxContainer/Num1SpinBox
@onready var number_two = $HBoxContainer/Num2SpinBox
@onready var result = $HBoxContainer/LabelTotal
# Called when the node enters the scene tree for the first time.
func _ready():
print(go.multiply(6, 7))
func _on_button_pressed() -> void:
result.text = "calculated: " + str(go.multiply(int(number_one.value), int(number_two.value))) package main
import (
"graphics.gd/classdb"
"graphics.gd/startup"
"graphics.gd/variant/RefCounted"
)
type GoUtils struct {
classdb.Extension[GoUtils, RefCounted.Instance] `gd:"GoUtils"`
}
func (utils *GoUtils) Multiply(a, b int32) int32 { return a * b }
func main() {
classdb.Register[GoUtils]()
startup.Scene()
} Godot-Rust Exampleextends Node2D
@onready var rust = RustUtils.new()
@onready var number_one = $VBoxContainer/HBoxContainer/Num1SpinBox
@onready var number_two = $VBoxContainer/HBoxContainer/Num2SpinBox
@onready var result = $VBoxContainer/HBoxContainer/LabelTotal
@onready var hellolabel = $VBoxContainer/HBoxContainer2/HelloLabel
@onready var helloLineEdit = $VBoxContainer/HBoxContainer2/HelloLineEdit
@onready var helloButton = $VBoxContainer/HBoxContainer2/HelloButton
var helloname: String = ""
# Called when the node enters the scene tree for the first time.
func _ready():
print(rust.multiply(6, 7))
func _on_button_pressed() -> void:
result.text = str(rust.multiply(int(number_one.value), int(number_two.value)))
func _on_hello_button_pressed() -> void:
hellolabel.text =str(rust.hello(helloLineEdit.text)) use godot::prelude::*;
#[derive(GodotClass)]
#[class(base=RefCounted, init)]
pub struct RustUtils {
#[base]
base: Base<RefCounted>,
}
#[godot_api]
impl RustUtils {
#[func]
fn multiply(&self, a: i32, b: i32) -> i32 {
a * b
}
#[func]
fn hello(&self, name: String) -> String {
format!("Hello {}!", name)
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
nmerget
May 28, 2025
Replies: 1 comment 1 reply
-
Hey, @KameiKojirou at the moment the It might be possible if |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
KameiKojirou
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, @KameiKojirou at the moment the
new
method is not implemented.It might be possible if
new
would be implemented correctly