summaryrefslogtreecommitdiff
path: root/modules/gdnative/pluginscript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdnative/pluginscript')
-rw-r--r--modules/gdnative/pluginscript/SCsub7
-rw-r--r--modules/gdnative/pluginscript/pluginscript_instance.cpp4
-rw-r--r--modules/gdnative/pluginscript/pluginscript_instance.h4
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.cpp13
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.h12
-rw-r--r--modules/gdnative/pluginscript/pluginscript_loader.cpp6
-rw-r--r--modules/gdnative/pluginscript/pluginscript_loader.h14
-rw-r--r--modules/gdnative/pluginscript/pluginscript_script.cpp90
-rw-r--r--modules/gdnative/pluginscript/pluginscript_script.h10
-rw-r--r--modules/gdnative/pluginscript/register_types.cpp12
-rw-r--r--modules/gdnative/pluginscript/register_types.h4
11 files changed, 121 insertions, 55 deletions
diff --git a/modules/gdnative/pluginscript/SCsub b/modules/gdnative/pluginscript/SCsub
index 2031a4236b..20eaa99592 100644
--- a/modules/gdnative/pluginscript/SCsub
+++ b/modules/gdnative/pluginscript/SCsub
@@ -1,9 +1,6 @@
#!/usr/bin/env python
Import('env')
-Import('env_modules')
+Import('env_gdnative')
-env_pluginscript = env_modules.Clone()
-
-env_pluginscript.Append(CPPPATH=['#modules/gdnative/include/'])
-env_pluginscript.add_source_files(env.modules_sources, '*.cpp')
+env_gdnative.add_source_files(env.modules_sources, '*.cpp')
diff --git a/modules/gdnative/pluginscript/pluginscript_instance.cpp b/modules/gdnative/pluginscript/pluginscript_instance.cpp
index 13026e8e7a..4b5dcc2c11 100644
--- a/modules/gdnative/pluginscript/pluginscript_instance.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_instance.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/modules/gdnative/pluginscript/pluginscript_instance.h b/modules/gdnative/pluginscript/pluginscript_instance.h
index 8be6a4ccaa..b279fdad8b 100644
--- a/modules/gdnative/pluginscript/pluginscript_instance.h
+++ b/modules/gdnative/pluginscript/pluginscript_instance.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/modules/gdnative/pluginscript/pluginscript_language.cpp b/modules/gdnative/pluginscript/pluginscript_language.cpp
index 2b538c4a36..c9d92c09ed 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_language.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -173,8 +173,7 @@ Error PluginScriptLanguage::complete_code(const String &p_code, const String &p_
for (int i = 0; i < options.size(); i++) {
r_options->push_back(String(options[i]));
}
- Error err = *(Error *)&tmp;
- return err;
+ return (Error)tmp;
}
return ERR_UNAVAILABLE;
}
@@ -417,8 +416,8 @@ void PluginScriptLanguage::unlock() {
PluginScriptLanguage::PluginScriptLanguage(const godot_pluginscript_language_desc *desc) :
_desc(*desc) {
- _resource_loader = memnew(ResourceFormatLoaderPluginScript(this));
- _resource_saver = memnew(ResourceFormatSaverPluginScript(this));
+ _resource_loader = Ref<ResourceFormatLoaderPluginScript>(memnew(ResourceFormatLoaderPluginScript(this)));
+ _resource_saver = Ref<ResourceFormatSaverPluginScript>(memnew(ResourceFormatSaverPluginScript(this)));
// TODO: totally remove _lock attribute if NO_THREADS is set
#ifdef NO_THREADS
@@ -429,8 +428,6 @@ PluginScriptLanguage::PluginScriptLanguage(const godot_pluginscript_language_des
}
PluginScriptLanguage::~PluginScriptLanguage() {
- memdelete(_resource_loader);
- memdelete(_resource_saver);
#ifndef NO_THREADS
if (_lock) {
memdelete(_lock);
diff --git a/modules/gdnative/pluginscript/pluginscript_language.h b/modules/gdnative/pluginscript/pluginscript_language.h
index c4df6f3a33..991be0bf12 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.h
+++ b/modules/gdnative/pluginscript/pluginscript_language.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -48,8 +48,8 @@ class PluginScriptLanguage : public ScriptLanguage {
friend class PluginScript;
friend class PluginScriptInstance;
- ResourceFormatLoaderPluginScript *_resource_loader;
- ResourceFormatSaverPluginScript *_resource_saver;
+ Ref<ResourceFormatLoaderPluginScript> _resource_loader;
+ Ref<ResourceFormatSaverPluginScript> _resource_saver;
const godot_pluginscript_language_desc _desc;
godot_pluginscript_language_data *_data;
@@ -59,8 +59,8 @@ class PluginScriptLanguage : public ScriptLanguage {
public:
virtual String get_name() const;
- _FORCE_INLINE_ ResourceFormatLoaderPluginScript *get_resource_loader() { return _resource_loader; };
- _FORCE_INLINE_ ResourceFormatSaverPluginScript *get_resource_saver() { return _resource_saver; };
+ _FORCE_INLINE_ Ref<ResourceFormatLoaderPluginScript> get_resource_loader() { return _resource_loader; }
+ _FORCE_INLINE_ Ref<ResourceFormatSaverPluginScript> get_resource_saver() { return _resource_saver; }
/* LANGUAGE FUNCTIONS */
virtual void init();
diff --git a/modules/gdnative/pluginscript/pluginscript_loader.cpp b/modules/gdnative/pluginscript/pluginscript_loader.cpp
index acba297fa0..c7ff8518b5 100644
--- a/modules/gdnative/pluginscript/pluginscript_loader.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_loader.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,7 +29,7 @@
/*************************************************************************/
// Godot imports
-#include "os/file_access.h"
+#include "core/os/file_access.h"
// Pythonscript imports
#include "pluginscript_language.h"
#include "pluginscript_loader.h"
diff --git a/modules/gdnative/pluginscript/pluginscript_loader.h b/modules/gdnative/pluginscript/pluginscript_loader.h
index 9276ea3ef9..69a2ac6bfe 100644
--- a/modules/gdnative/pluginscript/pluginscript_loader.h
+++ b/modules/gdnative/pluginscript/pluginscript_loader.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,13 +32,16 @@
#define PYTHONSCRIPT_PY_LOADER_H
// Godot imports
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
#include "core/script_language.h"
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
class PluginScriptLanguage;
class ResourceFormatLoaderPluginScript : public ResourceFormatLoader {
+
+ GDCLASS(ResourceFormatLoaderPluginScript, ResourceFormatLoader)
+
PluginScriptLanguage *_language;
public:
@@ -50,6 +53,9 @@ public:
};
class ResourceFormatSaverPluginScript : public ResourceFormatSaver {
+
+ GDCLASS(ResourceFormatSaverPluginScript, ResourceFormatSaver)
+
PluginScriptLanguage *_language;
public:
diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp
index c3a623e9a1..3450a032c5 100644
--- a/modules/gdnative/pluginscript/pluginscript_script.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_script.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -52,6 +52,79 @@
#endif
void PluginScript::_bind_methods() {
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &PluginScript::_new, MethodInfo(Variant::OBJECT, "new"));
+}
+
+PluginScriptInstance *PluginScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Variant::CallError &r_error) {
+
+ r_error.error = Variant::CallError::CALL_OK;
+
+ // Create instance
+ PluginScriptInstance *instance = memnew(PluginScriptInstance());
+
+ if (instance->init(this, p_owner)) {
+ _language->lock();
+ _instances.insert(instance->get_owner());
+ _language->unlock();
+ } else {
+ r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
+ memdelete(instance);
+ ERR_FAIL_V(NULL);
+ }
+
+ // Construct
+ // TODO: Support arguments in the constructor?
+ // There is currently no way to get the constructor function name of the script.
+ // instance->call("__init__", p_args, p_argcount, r_error);
+ if (p_argcount > 0) {
+ WARN_PRINT("PluginScript doesn't support arguments in the constructor")
+ }
+
+ return instance;
+}
+
+Variant PluginScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+
+ r_error.error = Variant::CallError::CALL_OK;
+
+ if (!_valid) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ return Variant();
+ }
+
+ REF ref;
+ Object *owner = NULL;
+
+ if (get_instance_base_type() == "") {
+ owner = memnew(Reference);
+ } else {
+ owner = ClassDB::instance(get_instance_base_type());
+ }
+
+ if (!owner) {
+ r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
+ return Variant();
+ }
+
+ Reference *r = Object::cast_to<Reference>(owner);
+ if (r) {
+ ref = REF(r);
+ }
+
+ PluginScriptInstance *instance = _create_instance(p_args, p_argcount, owner, r_error);
+
+ if (!instance) {
+ if (ref.is_null()) {
+ memdelete(owner); //no owner, sorry
+ }
+ return Variant();
+ }
+
+ if (ref.is_valid()) {
+ return ref;
+ } else {
+ return owner;
+ }
}
#ifdef TOOLS_ENABLED
@@ -129,17 +202,8 @@ ScriptInstance *PluginScript::instance_create(Object *p_this) {
}
}
- PluginScriptInstance *instance = memnew(PluginScriptInstance());
- const bool success = instance->init(this, p_this);
- if (success) {
- _language->lock();
- _instances.insert(instance->get_owner());
- _language->unlock();
- return instance;
- } else {
- memdelete(instance);
- ERR_FAIL_V(NULL);
- }
+ Variant::CallError unchecked_error;
+ return _create_instance(NULL, 0, p_this, unchecked_error);
}
bool PluginScript::instance_has(const Object *p_this) const {
diff --git a/modules/gdnative/pluginscript/pluginscript_script.h b/modules/gdnative/pluginscript/pluginscript_script.h
index 31c6c4d67f..0a84ccba0d 100644
--- a/modules/gdnative/pluginscript/pluginscript_script.h
+++ b/modules/gdnative/pluginscript/pluginscript_script.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,8 +37,6 @@
#include "pluginscript_language.h"
#include <pluginscript/godot_pluginscript.h>
-class PyInstance;
-
class PluginScript : public Script {
GDCLASS(PluginScript, Script);
@@ -74,6 +72,9 @@ private:
protected:
static void _bind_methods();
+ PluginScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Variant::CallError &r_error);
+ Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+
#ifdef TOOLS_ENABLED
Set<PlaceHolderScriptInstance *> placeholders;
//void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
@@ -102,6 +103,7 @@ public:
PropertyInfo get_property_info(const StringName &p_property) const;
bool is_tool() const { return _tool; }
+ bool is_valid() const { return true; }
virtual ScriptLanguage *get_language() const;
diff --git a/modules/gdnative/pluginscript/register_types.cpp b/modules/gdnative/pluginscript/register_types.cpp
index 924abf29df..b7ab887e11 100644
--- a/modules/gdnative/pluginscript/register_types.cpp
+++ b/modules/gdnative/pluginscript/register_types.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,11 +30,11 @@
#include "register_types.h"
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
+#include "core/os/dir_access.h"
+#include "core/os/os.h"
#include "core/project_settings.h"
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "os/dir_access.h"
-#include "os/os.h"
#include "scene/main/scene_tree.h"
#include "pluginscript_language.h"
diff --git a/modules/gdnative/pluginscript/register_types.h b/modules/gdnative/pluginscript/register_types.h
index 76651aa986..3114fb6b7d 100644
--- a/modules/gdnative/pluginscript/register_types.h
+++ b/modules/gdnative/pluginscript/register_types.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */