@@ -755,6 +755,9 @@ void QuickJSBinder::add_godot_globals() {
755755 // godot.register_property
756756 JSValue js_func_register_property = JS_NewCFunction (ctx, godot_register_property, " register_property" , 3 );
757757 JS_DefinePropertyValueStr (ctx, godot_object, " register_property" , js_func_register_property, PROP_DEF_DEFAULT);
758+ // godot.set_script_meta
759+ JSValue js_func_set_script_meta = JS_NewCFunction (ctx, godot_set_script_metadata, " set_script_meta" , 3 );
760+ JS_DefinePropertyValueStr (ctx, godot_object, " set_script_meta" , js_func_set_script_meta, PROP_DEF_DEFAULT);
758761 // godot.get_type
759762 JSValue js_get_type = JS_NewCFunction (ctx, godot_get_type, " get_type" , 1 );
760763 JS_DefinePropertyValueStr (ctx, godot_object, " get_type" , js_get_type, PROP_DEF_DEFAULT);
@@ -805,6 +808,8 @@ void QuickJSBinder::initialize() {
805808 js_key_godot_classid = JS_NewAtom (ctx, JS_HIDDEN_SYMBOL (" cls" ));
806809 js_key_godot_exports = JS_NewAtom (ctx, JS_HIDDEN_SYMBOL (" exports" ));
807810 js_key_godot_signals = JS_NewAtom (ctx, JS_HIDDEN_SYMBOL (" signals" ));
811+ js_key_godot_tooled = JS_NewAtom (ctx, JS_HIDDEN_SYMBOL (" tool" ));
812+ js_key_godot_icon_path = JS_NewAtom (ctx, JS_HIDDEN_SYMBOL (" icon" ));
808813 JS_DefinePropertyValueStr (ctx, global_object, GODOT_OBJECT_NAME, godot_object, PROP_DEF_DEFAULT);
809814 // godot.GodotOrigin
810815 add_godot_origin ();
@@ -856,6 +861,8 @@ void QuickJSBinder::uninitialize() {
856861 module_cache.clear ();
857862
858863 JS_FreeAtom (ctx, js_key_godot_classid);
864+ JS_FreeAtom (ctx, js_key_godot_tooled);
865+ JS_FreeAtom (ctx, js_key_godot_icon_path);
859866 JS_FreeAtom (ctx, js_key_godot_exports);
860867 JS_FreeAtom (ctx, js_key_godot_signals);
861868 JS_FreeValue (ctx, empty_function);
@@ -1072,6 +1079,8 @@ const ECMAClassInfo *QuickJSBinder::register_ecma_class(const JSValue &p_constru
10721079 QuickJSBinder *binder = get_context_binder (ctx);
10731080 JSValue prototype = JS_UNDEFINED;
10741081 JSValue classid = JS_UNDEFINED;
1082+ JSValue tooled = JS_UNDEFINED;
1083+ JSValue icon = JS_UNDEFINED;
10751084 JSClassID id = 0 ;
10761085
10771086 if (!JS_IsFunction (ctx, p_constructor)) {
@@ -1081,6 +1090,9 @@ const ECMAClassInfo *QuickJSBinder::register_ecma_class(const JSValue &p_constru
10811090
10821091 prototype = JS_GetProperty (ctx, p_constructor, QuickJSBinder::JS_ATOM_prototype);
10831092 classid = JS_GetProperty (ctx, prototype, js_key_godot_classid);
1093+ tooled = JS_GetProperty (ctx, p_constructor, js_key_godot_tooled);
1094+ icon = JS_GetProperty (ctx, p_constructor, js_key_godot_icon_path);
1095+
10841096 if (JS_IsUndefined (classid)) {
10851097 JS_ThrowTypeError (ctx, " ECMAClass class expected: %s" , p_path.utf8 ().ptr ());
10861098 goto fail;
@@ -1102,6 +1114,10 @@ const ECMAClassInfo *QuickJSBinder::register_ecma_class(const JSValue &p_constru
11021114 ecma_class.class_name = class_name;
11031115 ecma_class.prototype .ecma_object = JS_VALUE_GET_PTR (prototype);
11041116 ecma_class.constructor .ecma_object = JS_VALUE_GET_PTR (p_constructor);
1117+ ecma_class.tool = JS_ToBool (ctx, tooled);
1118+ if (JS_IsString (icon)) {
1119+ ecma_class.icon_path = js_to_string (ctx, icon);
1120+ }
11051121
11061122 // signals
11071123 JSValue signals = JS_GetProperty (ctx, prototype, js_key_godot_signals);
@@ -1149,6 +1165,8 @@ const ECMAClassInfo *QuickJSBinder::register_ecma_class(const JSValue &p_constru
11491165fail:
11501166 JS_FreeValue (ctx, classid);
11511167 JS_FreeValue (ctx, prototype);
1168+ JS_FreeValue (ctx, icon);
1169+ JS_FreeValue (ctx, tooled);
11521170 return binder->ecma_classes .getptr (p_path);
11531171}
11541172
@@ -1213,6 +1231,18 @@ JSValue QuickJSBinder::godot_register_property(JSContext *ctx, JSValue this_val,
12131231 return JS_UNDEFINED;
12141232}
12151233
1234+ JSValue QuickJSBinder::godot_set_script_metadata (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
1235+ ERR_FAIL_COND_V (argc < 2 , JS_ThrowTypeError (ctx, " Two or more arguments expected" ))
1236+ ERR_FAIL_COND_V (!JS_IsFunction (ctx, argv[0 ]), JS_ThrowTypeError (ctx, " godot class expected for argument #0" ));
1237+ JSValue constructor = argv[0 ];
1238+ QuickJSBinder *binder = get_context_binder (ctx);
1239+ JS_SetProperty (ctx, constructor, binder->js_key_godot_tooled , JS_DupValue (ctx, argv[1 ]));
1240+ if (argc >= 3 && JS_IsString (argv[2 ])) {
1241+ JS_SetProperty (ctx, constructor, binder->js_key_godot_tooled , JS_DupValue (ctx, argv[2 ]));
1242+ }
1243+ return JS_UNDEFINED;
1244+ }
1245+
12161246int QuickJSBinder::get_js_array_length (JSContext *ctx, JSValue p_val) {
12171247 if (!JS_IsArray (ctx, p_val)) return -1 ;
12181248 JSValue ret = JS_GetProperty (ctx, p_val, JS_ATOM_length);
0 commit comments