├── .editorconfig ├── .gitignore ├── .gitmodules ├── .travis.yml ├── LICENSE ├── README.md ├── build.sh ├── ext ├── .gitignore ├── Makefile ├── godot.yml ├── godot_binding.cpp └── godot_helper.cpp ├── shard.yml ├── spec ├── godot-crystal_spec.cr └── spec_helper.cr └── src ├── godot-crystal.cr └── godot ├── array.cr └── object.cr /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*.cr] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /docs/ 2 | /lib/ 3 | /bin/ 4 | /.shards/ 5 | *.dwarf 6 | 7 | # Libraries don't need dependency lock 8 | # Dependencies will be locked in applications that use them 9 | /shard.lock 10 | 11 | src/ext/godot_binding.cr 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ext/godot-cpp"] 2 | path = ext/godot-cpp 3 | url = https://github.com/GodotNativeTools/godot-cpp 4 | [submodule "ext/godot_headers"] 5 | path = ext/godot_headers 6 | url = https://github.com/GodotNativeTools/godot_headers 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: crystal 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Holden Omans 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # godot-crystal 2 | 3 | The goal of this project is to provide Crystal bindings for the [Godot](http://godotengine.org) game engine. 4 | 5 | ## Installation 6 | 7 | Right now, this lib uses [bindgen](https://github.com/Papierkorb/bindgen) to generate the bindings, so please review 8 | the requirements for bindgen before use. 9 | 10 | You can run the provided `build.sh` script which should automate the building of the bindings. 11 | 12 | ## Contributing 13 | 14 | 1. Fork it () 15 | 2. Create your feature branch (`git checkout -b my-new-feature`) 16 | 3. Commit your changes (`git commit -am 'Add some feature'`) 17 | 4. Push to the branch (`git push origin my-new-feature`) 18 | 5. Create a new Pull Request 19 | 20 | ## Contributors 21 | 22 | - [Holden Omans](https://github.com/kalinon) - creator and maintainer 23 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | root_dir=$(pwd) 6 | 7 | cd_root() { 8 | cd ${root_dir} 9 | } 10 | 11 | make_clean() { 12 | cd ./ext 13 | make clean 14 | cd_root 15 | } 16 | 17 | # Update submodules 18 | git submodule update --init --recursive 19 | 20 | # Check bindgen 21 | if [ ! -e ./lib/bindgen/clang/bindgen ]; then 22 | cd ./lib/bindgen 23 | cmake . 24 | make 25 | cd_root 26 | fi 27 | 28 | if [ ! -e ./lib/bindgen/bin/bindgen ]; then 29 | ./lib/bindgen 30 | cmake . 31 | make 32 | cd_root 33 | fi 34 | 35 | # Generate bindings 36 | if [ ! -e ./ext/godot-cpp/bin/libgodot-cpp.osx.debug.64.a ]; then 37 | cd ext/godot-cpp 38 | scons platform=osx generate_bindings=yes use_llvm=yes 39 | cd_root 40 | fi 41 | 42 | make_clean 43 | 44 | ./lib/bindgen/bin/bindgen ext/godot.yml 45 | 46 | cd_root 47 | 48 | crystal tool format 49 | crystal docs 50 | -------------------------------------------------------------------------------- /ext/.gitignore: -------------------------------------------------------------------------------- 1 | godot_binding.a 2 | godot_binding.o 3 | -------------------------------------------------------------------------------- /ext/Makefile: -------------------------------------------------------------------------------- 1 | CXXFLAGS := -Wall -Werror -Wno-unused-function -fPIC -I. -I./godot-cpp/include -I./godot-cpp/include/core -I./godot-cpp/include/gen -I./godot_headers 2 | CPPFILES := godot_binding.cpp 3 | OBJFILES := $(CPPFILES:.cpp=.o) 4 | LIBFILE := godot_binding.a 5 | 6 | CC ?= g++ 7 | AR ?= ar 8 | RM ?= rm 9 | 10 | all: $(LIBFILE) 11 | 12 | clean: 13 | $(RM) -f $(OBJFILES) 14 | $(RM) -f $(LIBFILE) 15 | 16 | $(LIBFILE): $(OBJFILES) 17 | $(AR) rcs $@ $^ 18 | 19 | %.o: %.cpp 20 | $(CC) -std=c++11 -c -o $@ $< $(CXXFLAGS) 21 | 22 | .PHONY: clean 23 | -------------------------------------------------------------------------------- /ext/godot.yml: -------------------------------------------------------------------------------- 1 | module: GodotLib 2 | generators: 3 | crystal: 4 | output: src/ext/godot_binding.cr 5 | # cpp: 6 | # output: ext/godot_binding.cpp 7 | # preamble: |- 8 | # #define protected public 9 | # build: make 10 | 11 | find_paths: 12 | LLVM_CONFIG_BINARY: 13 | kind: Executable 14 | optional: false 15 | try: 16 | - llvm-config 17 | version: 18 | min: "4" 19 | max: "6" 20 | variable: LLVM_VERSION 21 | command: "% --version" 22 | regex: "^([0-9]+)." 23 | error_message: Failed to find llvm version 24 | LLVM_DIR: 25 | kind: Directory 26 | optional: false 27 | list: false 28 | try: 29 | - shell: "{LLVM_CONFIG_BINARY} --ldflags" 30 | regex: "-L([^ ]+)/lib" 31 | multiple: false 32 | LLVM_INCLUDES: 33 | kind: Directory 34 | optional: false 35 | list: 36 | separator: " -I" 37 | template: "%" 38 | try: 39 | - "{LLVM_DIR}/include/c++/v1" 40 | - "{LLVM_DIR}/lib/clang/*/include" 41 | CLANG_BINARY: 42 | kind: Executable 43 | optional: false 44 | search_paths: 45 | - "{LLVM_DIR}" 46 | try: 47 | - "bin/clang++" 48 | version: 49 | min: "4" 50 | max: "6" 51 | variable: CLANG_VERSION 52 | command: "% --version" 53 | regex: "^clang version ([0-9]+)." 54 | 55 | classes: 56 | Variant: Variant 57 | Color: Color 58 | Vector2: Vector2 59 | Rect2: Rect2 60 | Vector3: Vector3 61 | Plane: Plane 62 | AABB: AABB 63 | Quat: Quat 64 | Basis: Basis 65 | Transform2D: Transform2D 66 | Transform: Transform 67 | NodePath: NodePath 68 | RID: RID 69 | Object: GObject 70 | Dictionary: Dictionary 71 | Array: Array 72 | PoolByteArray: PoolByteArray 73 | PoolIntArray: PoolIntArray 74 | PoolRealArray: PoolRealArray 75 | PoolStringArray: PoolStringArray 76 | PoolVector2Array: PoolVector2Array 77 | PoolVector3Array: PoolVector3Array 78 | PoolColorArray: PoolColorArray 79 | Point2: Point2 80 | Size2: Size2 81 | ClockDirection: ClockDirection 82 | Reference: Reference 83 | Sprite: Sprite 84 | Texture: Texture 85 | 86 | enums: 87 | Error: GError 88 | "Variant::Type": Enum::Variant::Type 89 | "Variant::Operator": Enum::Variant::Operator 90 | 91 | types: 92 | "signed char": 93 | builtin: true 94 | crystal_type: Char 95 | to_cpp: "signed char(%)" 96 | from_cpp: "static_cast(%.unicode())" 97 | to_crystal: "(%.chr)" 98 | from_crystal: "(%.ord)" 99 | kind: Struct 100 | pass_by: Value 101 | wchar_t: 102 | builtin: true 103 | crystal_type: Char 104 | to_cpp: "signed char(%)" 105 | from_cpp: "static_cast(%.unicode())" 106 | to_crystal: "(%.chr)" 107 | from_crystal: "(%.ord)" 108 | kind: Struct 109 | pass_by: Value 110 | real_t: 111 | alias_for: float 112 | "godot::String": 113 | converter: Godot::Converter::GdotString 114 | crystal_type: String 115 | cpp_type: CrystalString 116 | binding_type: CrystalString 117 | to_cpp: "GdotString::fromUtf8(%.ptr, %.size)" 118 | from_cpp: "gdotstring_to_crystal(%)" 119 | kind: Struct 120 | builtin: true 121 | pass_by: Value 122 | wrapper_pass_by: Value 123 | "godot::Color": 124 | alias_for: Color 125 | # "godot::Array": 126 | # alias_for: Array 127 | 128 | "godot::Variant": 129 | alias_for: Variant 130 | "godot::Vector2": 131 | alias_for: Vector2 132 | "godot::Rect2": 133 | alias_for: Rect2 134 | "godot::Vector3": 135 | alias_for: Vector3 136 | "godot::Plane": 137 | alias_for: Plane 138 | "godot::AABB": 139 | alias_for: AABB 140 | "godot::Quat": 141 | alias_for: Quat 142 | "godot::Basis": 143 | alias_for: Basis 144 | "godot::Transform2D": 145 | alias_for: Transform2D 146 | "godot::Transform": 147 | alias_for: Transform 148 | "godot::NodePath": 149 | alias_for: NodePath 150 | "godot::RID": 151 | alias_for: RID 152 | "godot::Object": 153 | alias_for: Object 154 | "godot::Dictionary": 155 | alias_for: Dictionary 156 | "godot::Array": 157 | alias_for: Array 158 | "godot::PoolByteArray": 159 | alias_for: PoolByteArray 160 | "godot::PoolIntArray": 161 | alias_for: PoolIntArray 162 | "godot::PoolRealArray": 163 | alias_for: PoolRealArray 164 | "godot::PoolStringArray": 165 | alias_for: PoolStringArray 166 | "godot::PoolVector2Array": 167 | alias_for: PoolVector2Array 168 | "godot::PoolVector3Array": 169 | alias_for: PoolVector3Array 170 | "godot::PoolColorArray": 171 | alias_for: PoolColorArray 172 | "godot::Variant::Type": 173 | alias_for: Variant::Type 174 | "godot::Point2": 175 | alias_for: Point2 176 | "godot::Size2": 177 | alias_for: Size2 178 | "godot::ClockDirection": 179 | alias_for: ClockDirection 180 | "godot::Error": 181 | alias_for: Error 182 | "godot::Reference": 183 | alias_for: Reference 184 | "godot::PoolByteArray::Read": 185 | ignore: true 186 | "godot::PoolByteArray::Write": 187 | ignore: true 188 | "godot::PoolIntArray::Read": 189 | ignore: true 190 | "godot::PoolIntArray::Write": 191 | ignore: true 192 | "godot::PoolRealArray::Read": 193 | ignore: true 194 | "godot::PoolRealArray::Write": 195 | ignore: true 196 | "godot::PoolStringArray::Read": 197 | ignore: true 198 | "godot::PoolStringArray::Write": 199 | ignore: true 200 | "godot::PoolVector2Array::Read": 201 | ignore: true 202 | "godot::PoolVector2Array::Write": 203 | ignore: true 204 | "godot::PoolVector3Array::Read": 205 | ignore: true 206 | "godot::PoolVector3Array::Write": 207 | ignore: true 208 | "godot::PoolColorArray::Read": 209 | ignore: true 210 | "godot::PoolColorArray::Write": 211 | ignore: true 212 | "godot::Sprite": 213 | alias_for: Sprite 214 | "godot::Texture": 215 | alias_for: Texture 216 | "godot::Ref": 217 | ignore: true 218 | parser: 219 | files: 220 | - godot_helper.cpp 221 | - core/AABB.hpp 222 | - core/Array.hpp 223 | - core/Basis.hpp 224 | - core/Color.hpp 225 | - core/CoreTypes.hpp 226 | - core/Defs.hpp 227 | - core/Dictionary.hpp 228 | - core/Godot.hpp 229 | - core/GodotGlobal.hpp 230 | - core/GodotProfiling.hpp 231 | - core/NodePath.hpp 232 | - core/Plane.hpp 233 | - core/PoolArrays.hpp 234 | - core/Quat.hpp 235 | - core/RID.hpp 236 | - core/Rect2.hpp 237 | - core/Ref.hpp 238 | - core/String.hpp 239 | - core/TagDB.hpp 240 | - core/Transform.hpp 241 | - core/Transform2D.hpp 242 | - core/Variant.hpp 243 | - core/Vector2.hpp 244 | - core/Vector3.hpp 245 | - core/Wrapped.hpp 246 | - Sprite.hpp 247 | includes: 248 | - "%" 249 | - "%/godot-cpp/include/" 250 | - "%/godot-cpp/include/core" 251 | - "%/godot-cpp/include/gen" 252 | - "%/godot-cpp/godot_headers" 253 | - "{LLVM_INCLUDES}" 254 | 255 | library: "%/ext/godot-cpp/bin/libgodot-cpp.osx.debug.64.a" 256 | -------------------------------------------------------------------------------- /ext/godot_binding.cpp: -------------------------------------------------------------------------------- 1 | #define protected public 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | -------------------------------------------------------------------------------- /ext/godot_helper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace godot; 5 | 6 | class SimpleClass : public Reference { 7 | GODOT_CLASS(SimpleClass, Reference); 8 | public: 9 | SimpleClass() { } 10 | 11 | /* _init must exist as it is called by Godot */ 12 | void _init() { } 13 | 14 | void test_void_method() { 15 | Godot::print("This is test"); 16 | } 17 | 18 | Variant method(Variant arg) { 19 | Variant ret; 20 | 21 | ret = arg; 22 | 23 | return ret; 24 | } 25 | 26 | static void _register_methods() { 27 | register_method("method", &SimpleClass::method); 28 | 29 | /** 30 | * How to register exports like gdscript 31 | * export var _name = "SimpleClass" 32 | **/ 33 | register_property("base/name", &SimpleClass::_name, String("SimpleClass")); 34 | 35 | /* or alternatively with getter and setter methods */ 36 | register_property("base/value", &SimpleClass::set_value, &SimpleClass::get_value, 0); 37 | 38 | /** For registering signal **/ 39 | // register_signal("signal_name"); 40 | // register_signal("signal_name", "string_argument", GODOT_VARIANT_TYPE_STRING) 41 | } 42 | 43 | String _name; 44 | int _value; 45 | 46 | void set_value(int p_value) { 47 | _value = p_value; 48 | } 49 | 50 | int get_value() const { 51 | return _value; 52 | } 53 | }; 54 | 55 | /** GDNative Initialize **/ 56 | extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options * o) { 57 | godot::Godot::gdnative_init(o); 58 | } 59 | 60 | /** GDNative Terminate **/ 61 | extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options * o) { 62 | godot::Godot::gdnative_terminate(o); 63 | } 64 | 65 | /** NativeScript Initialize **/ 66 | extern "C" void GDN_EXPORT godot_nativescript_init(void * handle) { 67 | godot::Godot::nativescript_init(handle); 68 | 69 | godot::register_class(); 70 | } 71 | -------------------------------------------------------------------------------- /shard.yml: -------------------------------------------------------------------------------- 1 | name: godot-crystal 2 | version: 0.1.0 3 | 4 | authors: 5 | - Holden Omans 6 | 7 | crystal: ">= 0.36.1, < 2.0.0" 8 | 9 | license: MIT 10 | 11 | dependencies: 12 | bindgen: 13 | github: kalinon/bindgen 14 | branch: cmake 15 | -------------------------------------------------------------------------------- /spec/godot-crystal_spec.cr: -------------------------------------------------------------------------------- 1 | require "./spec_helper" 2 | 3 | describe Godot::Crystal do 4 | # TODO: Write tests 5 | 6 | it "works" do 7 | false.should eq(true) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/spec_helper.cr: -------------------------------------------------------------------------------- 1 | require "spec" 2 | require "../src/godot-crystal" 3 | -------------------------------------------------------------------------------- /src/godot-crystal.cr: -------------------------------------------------------------------------------- 1 | require "./ext/godot_binding" 2 | 3 | # require "godot/*" 4 | 5 | # TODO: Write documentation for `Godot::Crystal` 6 | module Godot::Crystal 7 | VERSION = "0.1.0" 8 | 9 | # TODO: Put your code here 10 | end 11 | 12 | ::GodotLib::Sprite.new 13 | -------------------------------------------------------------------------------- /src/godot/array.cr: -------------------------------------------------------------------------------- 1 | module Godot 2 | class Array 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /src/godot/object.cr: -------------------------------------------------------------------------------- 1 | module Godot 2 | class Object 3 | end 4 | end 5 | --------------------------------------------------------------------------------