Skip to content

Instantly share code, notes, and snippets.

@Watson1978
Created January 28, 2012 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Watson1978/1693028 to your computer and use it in GitHub Desktop.
Save Watson1978/1693028 to your computer and use it in GitHub Desktop.
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);
#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) {}
require "mkmf"
$CFLAGS << ' -fobjc-gc '
create_makefile("Bridge")
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
require 'Bridge'
load_bridge_support_file 'Bridge.bridgesupport'
buf = vec3_create(1, 2, 3)
p buf
vec3_print(buf)
@Watson1978
Copy link
Author

$ rake
$ macruby test_bridge.rb 
#<Pointer:0x40049d080>
x = 1.000000
y = 2.000000
z = 3.000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment