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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
require 'optparse'
require 'json'
require 'set'
require 'active_support/core_ext/string'
require_relative './templates.rb'
options = {}
OptionParser.new do |parser|
parser.banner = "Usage: example.rb [options]"
parser.on("-gGLUE", "--glue=GLUE", "Path to file(defaults to ./glue.rb)") do |glue|
options[:glue] = glue
end
parser.on('-cCONFIG', '--config=CONFIG', 'Path to config file') do |config|
options[:config] = config
end
end.parse!
options[:glue] ||= './glue.json'
glue = JSON.parse(File.read(options[:glue]))
bound = {}
phase1 = {}
phase2 = {}
phase3 = {}
phase4 = {}
phase5 = {}
complete_phase1 = {}
complete_phase2 = {}
complete_phase3 = {}
complete_phase4 = {}
complete_phase5 = {}
result = ""
includes = %{
#include <raylib.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/class.h>
#include <mruby/numeric.h>
#include <mruby/string.h>
#include <stdlib.h>
}
defines = ""
init_body = ""
standard_types = ['bool', 'int', 'float', 'double', 'float', 'const char *', 'unsigned int', 'void']
# for displaying statistics
glue.first.each do |func, params|
if (func.rpartition(' ').first == 'void') && (params[0] == 'void')
phase1[func] = params
elsif (standard_types.include? func.rpartition(' ').first) && (params[0] == 'void')
phase2[func] = params
else
no_struct_param = true
params.each do |param|
if !(standard_types.include? param.rpartition(' ').first)
no_struct_param = false
break
end
end
if no_struct_param
if standard_types.include? func.rpartition(' ').first
phase3[func] = params
else
phase4[func] = params
end
else
phase5[func] = params
end
end
end
# generates functions
glue.first.each do |func, params|
# for now dont worry about params or returns
if func.rpartition(' ').first != 'void' || params[0] != 'void'
next
else
bound[func] = params
if phase1.include? func
complete_phase1[func] = params
elsif phase2.include? func
complete_phase2[func] = params
elsif phase3.include? func
complete_phase3[func] = params
elsif phase4.include? func
complete_phase4[func] = params
elsif phase5.include? func
complete_phase5[func] = params
end
end
body = "#{func.split(' ').last}();\nreturn mrb_nil_value();"
defines += Template.function(func.split(' ').last, body)
init_body += Template.init_module_function('test', func.split(' ').last.underscore, func.split(' ').last, "MRB_ARGS_NONE()")
end
init_body.prepend(Template.define_module('Test'))
result = %{
#{includes}
#{defines}
#{Template.base('test', init_body, nil)}
}
result += "//Bound Functions: #{bound.length} / #{phase1.length + phase2.length + phase3.length + phase4.length + phase5.length}\n"
result += "//Phase 1 Functions: #{complete_phase1.length} / #{phase1.length}\n"
result += "//Phase 2 Functions: #{complete_phase2.length} / #{phase2.length}\n"
result += "//Phase 3 Functions: #{complete_phase3.length} / #{phase3.length}\n"
result += "//Phase 4 Functions: #{complete_phase4.length} / #{phase4.length}\n"
result += "//Phase 5 Functions: #{complete_phase5.length} / #{phase5.length}\n"
puts result
|