Skip to content

Commit

Permalink
add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxblade committed May 3, 2018
1 parent 9b27190 commit 41a63c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions c/SimpleDemo/makefile
@@ -0,0 +1,4 @@
all:
gcc -fPIC -shared -o bin/libplugin.so src/plugin.c
gcc -std=c11 -fPIC -c src/simple.c -I/home/cichol/godot_headers/ -I./src -o src/simple.os
gcc -shared -L./bin -lplugin -Wall src/simple.os -o bin/libsimple.so
5 changes: 5 additions & 0 deletions c/SimpleDemo/src/plugin.c
@@ -0,0 +1,5 @@
#include <stdio.h>

void hello(){
printf("hello\n");
}
1 change: 1 addition & 0 deletions c/SimpleDemo/src/plugin.h
@@ -0,0 +1 @@
void hello();
7 changes: 5 additions & 2 deletions c/SimpleDemo/src/simple.c
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <plugin.h>

typedef struct user_data_struct {
char data[256];
Expand All @@ -25,7 +26,7 @@ void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *p_options) {
}; break;
default: break;
};
};
};
}

void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *p_options) {
Expand All @@ -34,6 +35,8 @@ void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *p_opt
}

void GDN_EXPORT godot_nativescript_init(void *p_handle) {
hello();

godot_instance_create_func create = { NULL, NULL, NULL };
create.create_func = &simple_constructor;

Expand All @@ -52,7 +55,7 @@ void GDN_EXPORT godot_nativescript_init(void *p_handle) {

GDCALLINGCONV void *simple_constructor(godot_object *p_instance, void *p_method_data) {
printf("SIMPLE._init()\n");

user_data_struct *user_data = api->godot_alloc(sizeof(user_data_struct));
strcpy(user_data->data, "World from GDNative!");

Expand Down

0 comments on commit 41a63c6

Please sign in to comment.