@@ -1196,23 +1196,49 @@ void GDScriptByteCodeGenerator::write_call_builtin_type_static(const Address &p_
11961196}
11971197
11981198void GDScriptByteCodeGenerator::write_call_native_static (const Address &p_target, const StringName &p_class, const StringName &p_method, const Vector<Address> &p_arguments) {
1199- bool is_validated = false ;
1200-
12011199 MethodBind *method = ClassDB::get_method (p_class, p_method);
12021200
1203- if (!is_validated) {
1204- // Perform regular call.
1205- append_opcode_and_argcount (GDScriptFunction::OPCODE_CALL_NATIVE_STATIC, p_arguments.size () + 1 );
1206- for (int i = 0 ; i < p_arguments.size (); i++) {
1207- append (p_arguments[i]);
1201+ // Perform regular call.
1202+ append_opcode_and_argcount (GDScriptFunction::OPCODE_CALL_NATIVE_STATIC, p_arguments.size () + 1 );
1203+ for (int i = 0 ; i < p_arguments.size (); i++) {
1204+ append (p_arguments[i]);
1205+ }
1206+ CallTarget ct = get_call_target (p_target);
1207+ append (ct.target );
1208+ append (method);
1209+ append (p_arguments.size ());
1210+ ct.cleanup ();
1211+ return ;
1212+ }
1213+
1214+ void GDScriptByteCodeGenerator::write_call_native_static_validated (const GDScriptCodeGenerator::Address &p_target, MethodBind *p_method, const Vector<GDScriptCodeGenerator::Address> &p_arguments) {
1215+ Variant::Type return_type = Variant::NIL;
1216+ bool has_return = p_method->has_return ();
1217+
1218+ if (has_return) {
1219+ PropertyInfo return_info = p_method->get_return_info ();
1220+ return_type = return_info.type ;
1221+ }
1222+
1223+ CallTarget ct = get_call_target (p_target, return_type);
1224+
1225+ if (has_return) {
1226+ Variant::Type temp_type = temporaries[ct.target .address ].type ;
1227+ if (temp_type != return_type) {
1228+ write_type_adjust (ct.target , return_type);
12081229 }
1209- CallTarget ct = get_call_target (p_target);
1210- append (ct.target );
1211- append (method);
1212- append (p_arguments.size ());
1213- ct.cleanup ();
1214- return ;
12151230 }
1231+
1232+ GDScriptFunction::Opcode code = p_method->has_return () ? GDScriptFunction::OPCODE_CALL_NATIVE_STATIC_VALIDATED_RETURN : GDScriptFunction::OPCODE_CALL_NATIVE_STATIC_VALIDATED_NO_RETURN;
1233+ append_opcode_and_argcount (code, 1 + p_arguments.size ());
1234+
1235+ for (int i = 0 ; i < p_arguments.size (); i++) {
1236+ append (p_arguments[i]);
1237+ }
1238+ append (ct.target );
1239+ append (p_arguments.size ());
1240+ append (p_method);
1241+ ct.cleanup ();
12161242}
12171243
12181244void GDScriptByteCodeGenerator::write_call_method_bind (const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) {
0 commit comments