Created
January 28, 2012 06:21
-
-
Save Watson1978/1693028 to your computer and use it in GitHub Desktop.
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
typedef struct _vec3_t { float x; float y; float z; } vec3_t; // Bridgesupport ignores unions with anonymous structs apparently | |
vec3_t* vec3_create(float a, float b, float c); | |
void vec3_print(vec3_t* data); |
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
#import <Foundation/Foundation.h> | |
union _vec3_t { | |
float f[3]; | |
struct { float x; float y; float z; }; | |
struct { float r; float g; float b; }; | |
//struct { vec2_t xy; float andY; }; | |
}; | |
typedef union _vec3_t vec3_t; | |
vec3_t* | |
vec3_create(float a, float b, float c) | |
{ | |
static vec3_t buf; | |
buf.f[0] = a; | |
buf.f[1] = b; | |
buf.f[2] = c; | |
return &buf; | |
} | |
void vec3_print(vec3_t* data) | |
{ | |
printf("x = %f\n", data->x); | |
printf("y = %f\n", data->y); | |
printf("z = %f\n", data->z); | |
} | |
// For MacRuby | |
void Init_Bridge(void) {} |
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
require "mkmf" | |
$CFLAGS << ' -fobjc-gc ' | |
create_makefile("Bridge") |
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
task :default do | |
sh "macruby extconf.rb" | |
sh "make" | |
sh "gen_bridge_metadata -c '-I.' bridge.h > Bridge.bridgesupport" | |
end | |
task :clean do | |
sh "make clean" | |
sh "rm Bridge.bridgesupport" | |
sh "rm Makefile" | |
end |
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
require 'Bridge' | |
load_bridge_support_file 'Bridge.bridgesupport' | |
buf = vec3_create(1, 2, 3) | |
p buf | |
vec3_print(buf) |
Author
Watson1978
commented
Jan 28, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment