summaryrefslogtreecommitdiffhomepage
path: root/ideas/stuff.rb
blob: 9e4cba777c047934c1389d1e3d6ba37bc4d66e5b (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal:true

# ---

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

mgem.add_class("BasicExample")

mgem.add_function(class_name: "BasicExample", function_name: "say_hello") do |func|
  func.content = "printf(\"Hello World\n\");"
  func.return_call do |rc|
    rc.type = "nil"
  end
end

puts mgem.build

# ---

mgem = FelBind::BindGem.new

mgem.add_class("ArgumentsAndReturnExample")

mgem.add_function(class: "ArgumentsAndReturnExample", name: "multiply_numbers") do |func|
  func.get_args do |args|
    args.int "first_input"
    args.int "second_input"
  end

  func.return_call do |rc|
    rc.type = "int"
    rc.val = "#{func.arg("first_input")} * #{func.arg("second_input")}"
  end
end

# ---

mgem = BindGem.new

mgem.add_class("KeywordArgumentsExample")

mgem.add_function(class: "KeywordArgumentsExample", name: "multiply_numbers") do |func|
  func.get_kwargs do |kwargs|
    kwargs.args x: "int", y: "int"
  end

  func.return_call do |rc|
    rc.rtype = "int"
    rc.val = "#{func.kwarg("x")} * #{func.kwarg("y")}"
  end
end

# ---

mgem = BindGem.new

mgem.add_class("Color")

mgem.add_struct(class: "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