generated from godotengine/godot-cpp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
126 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef GDS7_H | ||
#define GDS7_H | ||
|
||
#include "s7.hpp" | ||
#include "scheme_script.hpp" | ||
#include <godot_cpp/classes/node.hpp> | ||
#include <godot_cpp/variant/typed_array.hpp> | ||
|
||
namespace godot { | ||
class Scheme : public Node { | ||
GDCLASS(Scheme, Node) | ||
|
||
public: | ||
Scheme(); | ||
~Scheme() override; | ||
|
||
void _ready() override; | ||
void _process(double delta) override; | ||
void _exit_tree() override; | ||
|
||
void define(const String &name, const Variant &value, const String &help = "") const; | ||
void load(const SchemeScript *script) const; | ||
void load_string(const String &code) const; | ||
Variant eval(const String &code); | ||
Variant apply(const String &symbol, const Array &args) const; | ||
void set_prelude(const TypedArray<SchemeScript> &p_prelude) { prelude = p_prelude; } | ||
[[nodiscard]] TypedArray<SchemeScript> get_prelude() const { return prelude; } | ||
void set_scheme_script(const Ref<SchemeScript> &p_scheme_script); | ||
[[nodiscard]] Ref<SchemeScript> get_scheme_script() const { return scheme_script; }; | ||
|
||
[[nodiscard]] const s7 &get_s7() const { return s7; } | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
private: | ||
TypedArray<SchemeScript> prelude; | ||
Ref<SchemeScript> scheme_script; | ||
s7_protected_ptr _process_symbol; | ||
s7 s7; | ||
}; | ||
|
||
} // namespace godot | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
#include "scheme_callable.h" | ||
#include "ffi.h" | ||
#include "scheme_callable.hpp" | ||
#include "ffi.hpp" | ||
#include <godot_cpp/classes/object.hpp> | ||
#include <godot_cpp/variant/variant.hpp> | ||
|
||
using namespace godot; | ||
|
||
SchemeCallable::SchemeCallable(s7_scheme *sc, s7_pointer f, bool discard_return_value) : | ||
sc(sc), | ||
f(s7_gc_protected(sc, f)), | ||
discard_return_value(discard_return_value) { | ||
sc(sc), | ||
f(s7_gc_protected(sc, f)), | ||
discard_return_value(discard_return_value) { | ||
} | ||
|
||
uint32_t SchemeCallable::hash() const { | ||
return s7_hash_code(sc, f.get(), s7_unspecified(sc)); | ||
return s7_hash_code(sc, f.get(), s7_unspecified(sc)); | ||
} | ||
|
||
String SchemeCallable::get_as_text() const { | ||
return scheme_object_to_godot_string(sc, f.get()); | ||
return scheme_object_to_godot_string(sc, f.get()); | ||
} | ||
|
||
bool SchemeCallable::compare_equal_func(const CallableCustom *a, const CallableCustom *b) { | ||
if (a == b) { | ||
return true; | ||
} | ||
auto sc1 = dynamic_cast<const SchemeCallable *>(a); | ||
auto sc2 = dynamic_cast<const SchemeCallable *>(b); | ||
if (sc1 == sc2) { | ||
return true; | ||
} | ||
if (sc1 == nullptr || sc2 == nullptr) { | ||
return false; | ||
} | ||
auto sc = sc1->sc; | ||
if (sc2->sc != sc) { | ||
return false; | ||
} | ||
return s7_is_equal(sc, sc1->f.get(), sc2->f.get()); | ||
if (a == b) { | ||
return true; | ||
} | ||
auto sc1 = dynamic_cast<const SchemeCallable *>(a); | ||
auto sc2 = dynamic_cast<const SchemeCallable *>(b); | ||
if (sc1 == sc2) { | ||
return true; | ||
} | ||
if (sc1 == nullptr || sc2 == nullptr) { | ||
return false; | ||
} | ||
auto sc = sc1->sc; | ||
if (sc2->sc != sc) { | ||
return false; | ||
} | ||
return s7_is_equal(sc, sc1->f.get(), sc2->f.get()); | ||
} | ||
|
||
CallableCustom::CompareEqualFunc SchemeCallable::get_compare_equal_func() const { | ||
return &SchemeCallable::compare_equal_func; | ||
return &SchemeCallable::compare_equal_func; | ||
} | ||
|
||
bool SchemeCallable::compare_less_func(const CallableCustom *a, const CallableCustom *b) { | ||
return (void *)a < (void *)b; | ||
return (void *)a < (void *)b; | ||
} | ||
|
||
CallableCustom::CompareLessFunc SchemeCallable::get_compare_less_func() const { | ||
return &SchemeCallable::compare_less_func; | ||
return &SchemeCallable::compare_less_func; | ||
} | ||
|
||
bool SchemeCallable::is_valid() const { return true; } | ||
|
||
ObjectID SchemeCallable::get_object() const { | ||
auto node = s7_name_to_value(sc, "*node*"); | ||
if (is_variant(node)) { | ||
return ObjectID(variant_value(node)->operator Object *()->get_instance_id()); | ||
} | ||
return {}; | ||
auto node = s7_name_to_value(sc, "*node*"); | ||
if (is_variant(node)) { | ||
return ObjectID(variant_value(node)->operator Object *()->get_instance_id()); | ||
} | ||
return {}; | ||
} | ||
|
||
void SchemeCallable::call(const Variant **args, | ||
int arg_count, | ||
Variant &return_value, | ||
GDExtensionCallError &return_call_error) const { | ||
auto fp = f.get(); | ||
auto proc = fp; | ||
if (s7_is_symbol(fp)) { | ||
proc = s7_symbol_value(sc, fp); | ||
} | ||
int arg_count, | ||
Variant &return_value, | ||
GDExtensionCallError &return_call_error) const { | ||
auto fp = f.get(); | ||
auto proc = fp; | ||
if (s7_is_symbol(fp)) { | ||
proc = s7_symbol_value(sc, fp); | ||
} | ||
|
||
if (!s7_is_procedure(proc)) { | ||
return_call_error.error = GDEXTENSION_CALL_ERROR_INVALID_METHOD; | ||
return; | ||
} | ||
if (!s7_is_procedure(proc)) { | ||
return_call_error.error = GDEXTENSION_CALL_ERROR_INVALID_METHOD; | ||
return; | ||
} | ||
|
||
auto res = s7_call_with_location( | ||
sc, | ||
proc, | ||
variants_to_list(sc, args, arg_count), | ||
__func__, | ||
__FILE__, | ||
__LINE__); | ||
if (!discard_return_value) { | ||
return_value = scheme_to_variant(sc, res); | ||
} | ||
return_call_error.error = GDEXTENSION_CALL_OK; | ||
} | ||
auto res = s7_call_with_location( | ||
sc, | ||
proc, | ||
variants_to_list(sc, args, arg_count), | ||
__func__, | ||
__FILE__, | ||
__LINE__); | ||
if (!discard_return_value) { | ||
return_value = scheme_to_variant(sc, res); | ||
} | ||
return_call_error.error = GDEXTENSION_CALL_OK; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "scheme_object.h" | ||
#include "scheme_object.hpp" | ||
|
||
void godot::SchemeObject::_bind_methods() { | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.