summaryrefslogtreecommitdiffhomepage
path: root/mrb_gems/basic_struct_example/autogen.rb
blob: 4da090b414e70ae7f1926be5aad28b94d9e2358e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "FelBind"

mgem = FelBind::BindGem.new(gem_name: "basic_struct_example")

mgem.add_class("Color")

mgem.add_struct(class_name: "Color", cstruct_name: "Color") do |struct|
  struct.initializer = true
  struct.member(
    name: "r",
    ctype: "char",
    rtype: "int",
    accessor: true
  )
  struct.member(
    name: "g",
    ctype: "char",
    rtype: "int",
    accessor: true
  )
  struct.member(
    name: "b",
    ctype: "char",
    rtype: "int",
    accessor: true
  )
end

result = <<CCODE
typedef struct Color
{
	char r;
	char g;
	char b;
} Color;

Color color_shift(Color color)
{
  Color result = {
    .r = color.g,
    .g = color.a,
    .b = color.b
  }
  return result;
}
CCODE

result += mgem.build

File.write("src/basic_struct_example.c", result)