Watson1978
1/28/2012 - 6:21 AM

Rakefile

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
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")
require 'Bridge'
load_bridge_support_file 'Bridge.bridgesupport'

buf = vec3_create(1, 2, 3)
p buf
vec3_print(buf)