Skip to content

Commit

Permalink
Rename c++ header files to *.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
bamboo committed Nov 19, 2024
1 parent e646674 commit e60da83
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 124 deletions.
4 changes: 2 additions & 2 deletions src/debug_macros.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "debug_macros.h"
#include "debug_macros.hpp"

#if DEBUG_LOG

Expand All @@ -20,4 +20,4 @@ const Variant &watch_variant(const char *func, int line, const char *e, const Va
std::cout << func << ":" << line << ":" << e << ":" << v.stringify().utf8() << std::endl;
return v;
}
#endif
#endif
File renamed without changes.
12 changes: 6 additions & 6 deletions src/ffi.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ffi.h"
#include "debug_macros.h"
#include "ffi_macros.h"
#include "scheme_callable.h"
#include "scheme_object.h"
#include "ffi.hpp"
#include "debug_macros.hpp"
#include "ffi_macros.hpp"
#include "scheme_callable.hpp"
#include "scheme_object.hpp"

#include <godot_cpp/classes/performance.hpp>
#include <godot_cpp/core/class_db.hpp>
Expand Down Expand Up @@ -609,4 +609,4 @@ void define_variant_ffi(s7 &scheme) {
true,
"(print format &args) prints to the Godot console");
}
} //namespace godot
} //namespace godot
File renamed without changes.
File renamed without changes.
14 changes: 8 additions & 6 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "register_types.h"
#include "scheme.h"
#include "scheme_object.h"
#include "scheme_script.h"
#include "scheme_script_loader.h"
#include "scheme.hpp"
#include "scheme_object.hpp"
#include "scheme_script.hpp"
#include "scheme_script_loader.hpp"
#include <gdextension_interface.h>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/core/class_db.hpp>
Expand Down Expand Up @@ -36,8 +36,10 @@ void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {
}

extern "C" {
// Initialization
GDExtensionBool GDE_EXPORT godot_s7_scheme_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
GDExtensionBool GDE_EXPORT godot_s7_scheme_library_init(
GDExtensionInterfaceGetProcAddress p_get_proc_address,
GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization) {
GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
init_obj.register_initializer(initialize_gdextension_types);
init_obj.register_terminator(uninitialize_gdextension_types);
Expand Down
4 changes: 2 additions & 2 deletions src/s7.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include "s7.hpp"
#include "debug_macros.h"
#include "debug_macros.hpp"
#include <godot_cpp/variant/utility_functions.hpp>
#include <mutex>
#include <vector>
Expand Down Expand Up @@ -75,4 +75,4 @@ s7_pointer s7::define_constant_with_documentation(
const char *name, s7_pointer value, const char *help) const {
auto sc = get();
return s7_define_constant_with_documentation(sc, name, value, help);
}
}
4 changes: 2 additions & 2 deletions src/scheme.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "scheme.h"
#include "ffi.h"
#include "scheme.hpp"
#include "ffi.hpp"
#include "godot_cpp/variant/utility_functions.hpp"

using namespace godot;
Expand Down
45 changes: 0 additions & 45 deletions src/scheme.h

This file was deleted.

45 changes: 45 additions & 0 deletions src/scheme.hpp
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
110 changes: 55 additions & 55 deletions src/scheme_callable.cpp
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.
4 changes: 2 additions & 2 deletions src/scheme_object.cpp
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.
2 changes: 1 addition & 1 deletion src/scheme_script.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scheme_script.h"
#include "scheme_script.hpp"
#include <godot_cpp/core/class_db.hpp>

using namespace godot;
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/scheme_script_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "scheme_script_loader.h"
#include "scheme_script.h"
#include "scheme_script_loader.hpp"
#include "scheme_script.hpp"
#include <godot_cpp/classes/file_access.hpp>
#include <godot_cpp/core/class_db.hpp>

Expand Down Expand Up @@ -35,4 +35,4 @@ String SchemeScriptLoader::_get_resource_type(const String &p_path) const {
return "SchemeScript";
}
return "";
}
}
File renamed without changes.

0 comments on commit e60da83

Please sign in to comment.