summaryrefslogtreecommitdiff
path: root/modules/gdscript/gdscript_function.h
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_function.h')
-rw-r--r--modules/gdscript/gdscript_function.h113
1 files changed, 102 insertions, 11 deletions
diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h
index ea009dcd96..3ce84290fd 100644
--- a/modules/gdscript/gdscript_function.h
+++ b/modules/gdscript/gdscript_function.h
@@ -42,6 +42,95 @@
class GDScriptInstance;
class GDScript;
+struct GDScriptDataType {
+ bool has_type;
+ enum {
+ BUILTIN,
+ NATIVE,
+ SCRIPT,
+ GDSCRIPT
+ } kind;
+ Variant::Type builtin_type;
+ StringName native_type;
+ Ref<Script> script_type;
+
+ bool is_type(const Variant &p_variant, bool p_allow_implicit_conversion = false) const {
+ if (!has_type) return true; // Can't type check
+
+ switch (kind) {
+ case BUILTIN: {
+ Variant::Type var_type = p_variant.get_type();
+ bool valid = builtin_type == var_type;
+ if (!valid && p_allow_implicit_conversion) {
+ valid = Variant::can_convert_strict(var_type, builtin_type);
+ }
+ return valid;
+ } break;
+ case NATIVE: {
+ if (p_variant.get_type() == Variant::NIL) {
+ return true;
+ }
+ if (p_variant.get_type() != Variant::OBJECT) {
+ return false;
+ }
+ Object *obj = p_variant.operator Object *();
+ if (obj && !ClassDB::is_parent_class(obj->get_class_name(), native_type)) {
+ return false;
+ }
+ return true;
+ } break;
+ case SCRIPT:
+ case GDSCRIPT: {
+ if (p_variant.get_type() == Variant::NIL) {
+ return true;
+ }
+ if (p_variant.get_type() != Variant::OBJECT) {
+ return false;
+ }
+ Object *obj = p_variant.operator Object *();
+ Ref<Script> base = obj && obj->get_script_instance() ? obj->get_script_instance()->get_script() : NULL;
+ bool valid = false;
+ while (base.is_valid()) {
+ if (base == script_type) {
+ valid = true;
+ break;
+ }
+ base = base->get_base_script();
+ }
+ return valid;
+ } break;
+ }
+ return false;
+ }
+
+ operator PropertyInfo() const {
+ PropertyInfo info;
+ if (has_type) {
+ switch (kind) {
+ case BUILTIN: {
+ info.type = builtin_type;
+ } break;
+ case NATIVE: {
+ info.type = Variant::OBJECT;
+ info.class_name = native_type;
+ } break;
+ case SCRIPT:
+ case GDSCRIPT: {
+ info.type = Variant::OBJECT;
+ info.class_name = script_type->get_instance_base_type();
+ } break;
+ }
+ } else {
+ info.type = Variant::NIL;
+ info.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
+ }
+ return info;
+ }
+
+ GDScriptDataType() :
+ has_type(false) {}
+};
+
class GDScriptFunction {
public:
enum Opcode {
@@ -56,6 +145,12 @@ public:
OPCODE_ASSIGN,
OPCODE_ASSIGN_TRUE,
OPCODE_ASSIGN_FALSE,
+ OPCODE_ASSIGN_TYPED_BUILTIN,
+ OPCODE_ASSIGN_TYPED_NATIVE,
+ OPCODE_ASSIGN_TYPED_SCRIPT,
+ OPCODE_CAST_TO_BUILTIN,
+ OPCODE_CAST_TO_NATIVE,
+ OPCODE_CAST_TO_SCRIPT,
OPCODE_CONSTRUCT, //only for basic types!!
OPCODE_CONSTRUCT_ARRAY,
OPCODE_CONSTRUCT_DICTIONARY,
@@ -96,14 +191,6 @@ public:
ADDR_TYPE_NIL = 9
};
- enum RPCMode {
- RPC_DISABLED,
- RPC_ENABLED,
- RPC_SYNC,
- RPC_SYNC_MASTER,
- RPC_SYNC_SLAVE
- };
-
struct StackDebug {
int line;
@@ -135,7 +222,7 @@ private:
int _call_size;
int _initial_line;
bool _static;
- ScriptInstance::RPCMode rpc_mode;
+ MultiplayerAPI::RPCMode rpc_mode;
GDScript *_script;
@@ -147,6 +234,8 @@ private:
#endif
Vector<int> default_arguments;
Vector<int> code;
+ Vector<GDScriptDataType> argument_types;
+ GDScriptDataType return_type;
#ifdef TOOLS_ENABLED
Vector<StringName> arg_names;
@@ -207,6 +296,8 @@ public:
int get_max_stack_size() const;
int get_default_argument_count() const;
int get_default_argument_addr(int p_idx) const;
+ GDScriptDataType get_return_type() const;
+ GDScriptDataType get_argument_type(int p_idx) const;
GDScript *get_script() const { return _script; }
StringName get_source() const { return source; }
@@ -230,7 +321,7 @@ public:
Variant call(GDScriptInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err, CallState *p_state = NULL);
- _FORCE_INLINE_ ScriptInstance::RPCMode get_rpc_mode() const { return rpc_mode; }
+ _FORCE_INLINE_ MultiplayerAPI::RPCMode get_rpc_mode() const { return rpc_mode; }
GDScriptFunction();
~GDScriptFunction();
};
@@ -242,7 +333,7 @@ class GDScriptFunctionState : public Reference {
GDScriptFunction *function;
GDScriptFunction::CallState state;
Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
- Ref<GDScriptFunctionState> previous_state;
+ Ref<GDScriptFunctionState> first_state;
protected:
static void _bind_methods();