C++ bindings for the Godot script API
 
 
 
 
 
 
Go to file
Richy HBM b503db1712 Keep environment variables on windows
This ensures that environment variables are kept when on windows meaning you can run it with any version of VS, so long as you are in a VS prompt or have run the vcvars.bat file for your architecture
2017-07-29 11:50:05 +01:00
include/core Replaced 'char *' with 'const char *' for consistency with C API 2017-07-27 13:43:53 +03:00
src/core updated to use the new NativeScript and GDNative interface 2017-07-24 17:08:52 +02:00
.gitattributes Getting this to compile on mac os x 2017-06-16 23:50:48 +10:00
.gitignore Use static linking instead of dynamic linking 2017-07-23 17:53:50 +02:00
LICENSE Initial commit 2017-03-02 23:50:13 +01:00
README.md Update README.md 2017-07-26 08:50:23 +05:30
SConstruct Keep environment variables on windows 2017-07-29 11:50:05 +01:00
binding_generator.py updated to use the new NativeScript and GDNative interface 2017-07-24 17:08:52 +02:00

README.md

cpp_bindings

C++ bindings for the Godot script API

Creating a GDNative library (Linux)

Create a director named SimpleLibrary with subdirector lib, src

Getting latest cpp_bindings and godot_headers

$ cd SimpleLibrary
$ git clone https://github.com/GodotNativeTools/cpp_bindings
$ git clone https://github.com/GodotNativeTools/godot_headers

right now our file structure should look like this

[SimpleLibrary]
	├── cpp_bindings/
	├── godot_headers/
	├── lib/
	└── src/

Now to generate cpp bindings

$ cd cpp_bindings

Edit SConstruct file and assign your godot executable path at line:7 godot_bin_path = "../godot_fork/bin/",

Building cpp_bindings

$ scons p=linux

resulting libraries will be placed under bin/ and the generated headers will be placed under include/*

Note: Using generate_bindings=yes you can generate godot_api.json (Godot API) Use use_llvm=yes to use clang++.

Copy bindings librarys into SimpleLibrary/lib folder

$ cd ..
$ cp cpp_bindings/bin/libgodot_cpp_bindings.a lib/

And our file structure will be

[SimpleLibrary]
  ├── cpp_bindings/
  ├── godot_headers/
  ├── lib/
  │	  └──libgodot_cpp_bindings.a
  └── src/

Creating simple class

Create init.cpp under SimpleLibrary/src/ and add the following code

#include <core/Godot.hpp>
#include <Reference.hpp>

using namespace godot;

class SimpleClass : public GodotScript<Reference> {
        GODOT_CLASS(SimpleClass);
public:
        SimpleClass() { }

        void test_void_method() {
                Godot::print("This is test");
        }

        Variant method(Variant arg) {
            Variant ret;
            ret = arg;

            return ret;
        }

        static void _register_methods() {
           register_method("method", &SimpleClass::method);
	   
	   /**
	    * How to register exports like gdscript
	    * export var _name = "SimpleClass"
	    **/
	   register_property((char *)"base/name", &SimpleClass::_name, String("SimpleClass"));
        }
	
	String _name;
};

/** GDNative Initialize **/
GDNATIVE_INIT(godot_gdnative_init_options *options) {

}

/** GDNative Terminate **/
GDNATIVE_TERMINATE(godot_gdnative_terminate_options *options) {

}

/** NativeScript Initialize **/
NATIVESCRIPT_INIT() {
        register_class<SimpleClass>();
}

Compiling

$ cd ..
$ clang -fPIC -o src/init.os -c src/init.cpp -g -O3 -std=c++14 -Icpp_bindings/include -Igodot_headers -Icpp_bindings/include/
$ clang -o lib/libtest.so -shared src/init.os -Llib -lgodot_cpp_bindings

This creates the file libtest.so in your SimpleLibrary/lib directory. For windows you need to find out what compiler flags need to be used.

Creating .gdns file

follow godot_header/README.md to create the .gdns

Implementing with gdscript

var simpleclass = load("res://simpleclass.gdns").new();
simpleclass.method("Test argument");