nymph-generate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/nymph-generate +14 -0
- data/bin/setup +8 -0
- data/lib/nymph/generate/generator.rb +345 -0
- data/lib/nymph/generate/version.rb +5 -0
- data/lib/nymph/generate.rb +6 -0
- data/nymph-generate.gemspec +25 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7abd8ce8a53ddcb5c97bd4c5d39260f6cba060b5
|
4
|
+
data.tar.gz: ff3eee3f6f077d44841a67695bb73c45b569ee3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6350922e9d49b95cf95250a3b9dea886ced627a28d07544418615409facd6167489d54d3c7c3f02047b818c8bbd3ae6b78d49d45c15482e0e8b164bf2a2c1ff8
|
7
|
+
data.tar.gz: fc45511132abe02b6428346339fb198e818a065783d30db464070760d7b79b33cabda83aa3fa6ee5e3982b379c8e464561d909d8cbadd36e3a68a74a5eadf104
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nymph-generate (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (10.5.0)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
ruby
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
bundler (~> 1.16)
|
16
|
+
nymph-generate!
|
17
|
+
rake (~> 10.0)
|
18
|
+
|
19
|
+
BUNDLED WITH
|
20
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# nymph-generate
|
2
|
+
This is a git repository containing the code for the Ruby Gem nymph-generate to be used alongside the Nymph Game Engine.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'nymph-generate'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install nymph-generate
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
The output of `nymph-generate` will generate a C++ header file called `generated_registrations.h`. This contains all of the setup needed for adding specific c++ classes and methods to [Chaiscript](https://github.com/ChaiScript/ChaiScript).
|
22
|
+
|
23
|
+
After the gem is installed, running is as simple as:
|
24
|
+
```bash
|
25
|
+
nymph-generate
|
26
|
+
```
|
27
|
+
|
28
|
+
By default, `nymph-generate` will look for a directory called `src`, and search every file recursively within that directory. Also by default, it will drop the generated header into `src/generated/`. You can specify a directory to search, as well as directory to put the output header.
|
29
|
+
|
30
|
+
```bash
|
31
|
+
nymph-generate /path/of/source/to/search /path/of/header/destination
|
32
|
+
```
|
33
|
+
|
34
|
+
Within this header file is all of the necessary code to register your desired classes and methods into the chaiscript runtime. The only thing from this file that needs to be called is:
|
35
|
+
```c++
|
36
|
+
// generated_registrations.h
|
37
|
+
namespace generated {
|
38
|
+
...
|
39
|
+
...
|
40
|
+
void registerModules(std::shared_ptr<chaiscript::ChaiScript> chai);
|
41
|
+
...
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
45
|
+
All you have to give this function is a shared_ptr to the chaiscript object within your program. Make sure this is called before loading and running any scripts, otherwise they will not be there for your scripts to see.
|
46
|
+
|
47
|
+
## Flagging Header Files For Processing
|
48
|
+
There are flags that are used to let `nymph-generate` know which classes and methods to target. To let `nymph-generate` know that it needs to start processing, it looks for comments starting with `//=`. Right now there are 4 basic flags that one needs to know before being able to run `nymph-generate` on your project.
|
49
|
+
```c++
|
50
|
+
/* This marks a class as scriptable. This lets nymph-generate know that this class should
|
51
|
+
* be processed by nymph-generate. */
|
52
|
+
|
53
|
+
//= SCRIPTABLE
|
54
|
+
|
55
|
+
/* This marks the scriptable class as having base classes that are also scriptable within
|
56
|
+
* chaiscript. Only specify classes that are also scriptable themselves by listing their
|
57
|
+
* names exactly as they are defined and separated by spaces */
|
58
|
+
|
59
|
+
//= SCRIPTABLE BASES ClassName1 ClassName2 ...
|
60
|
+
|
61
|
+
/* This marks the beginning point of methods within a class that should be exposed within
|
62
|
+
* the chaiscript module. */
|
63
|
+
|
64
|
+
//= BEGIN SCRIPTABLE
|
65
|
+
|
66
|
+
/* This marks the ending point of methods within a class that should be exposed within
|
67
|
+
* the chaiscript module. */
|
68
|
+
|
69
|
+
//= END SCRIPTABLE
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. You can also run `bin/nymph-generate` to run this gem without installing it. This is good for development and testing.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). You can also run `bundle exec rake generate` to run this gem with rake without installing it.
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sainteos/nymph-generate.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nymph/generate"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/nymph-generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "bundler/setup"
|
3
|
+
require "nymph/generate"
|
4
|
+
require "nymph/generate/generator"
|
5
|
+
|
6
|
+
generator = Nymph::Generate::Generator.new
|
7
|
+
|
8
|
+
if ARGV.count == 2
|
9
|
+
generator.run ARGV[0], ARGV[1]
|
10
|
+
elsif ARGV.count == 1
|
11
|
+
generator.run ARGV[0], "#{ARGV[0]}/generated"
|
12
|
+
else
|
13
|
+
generator.run "#{`pwd`.chomp!}/src", "#{`pwd`.chomp!}/generated"
|
14
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,345 @@
|
|
1
|
+
module Nymph
|
2
|
+
module Generate
|
3
|
+
class Generator
|
4
|
+
def grabFiles directory
|
5
|
+
puts "Directory: #{directory}"
|
6
|
+
files = Dir.entries(directory)
|
7
|
+
files.collect! { |f| directory + f }
|
8
|
+
delete_files = []
|
9
|
+
files.each do |file|
|
10
|
+
if file =~ /.*\.\.?\Z/
|
11
|
+
delete_files.push file
|
12
|
+
elsif File.directory?(file)
|
13
|
+
delete_files.push file
|
14
|
+
files << grabFiles(file + "/")
|
15
|
+
files.flatten!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
files.delete_if { |f| delete_files.count(f) > 0 }
|
20
|
+
|
21
|
+
return files
|
22
|
+
end
|
23
|
+
|
24
|
+
def cullNonScriptableFiles files
|
25
|
+
h_files = []
|
26
|
+
|
27
|
+
files.each do |file|
|
28
|
+
if file =~ /\A.*\.hp{2}?\Z/
|
29
|
+
h_files << file
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
scriptable_files = []
|
34
|
+
scriptable_filenames = []
|
35
|
+
h_files.each do |filename|
|
36
|
+
file = File.readlines(filename).join("")
|
37
|
+
|
38
|
+
if file =~ /\s*\/\/=\s*SCRIPTABLE\s*$/
|
39
|
+
scriptable_filenames << filename
|
40
|
+
scriptable_files << file
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
return scriptable_files, scriptable_filenames
|
45
|
+
end
|
46
|
+
|
47
|
+
def extractNamespace file
|
48
|
+
namespace_regex = /\s*namespace\s+(\w+)\s*{\s*/
|
49
|
+
matches = file.scan(namespace_regex)
|
50
|
+
|
51
|
+
if matches.size > 0
|
52
|
+
return matches.join("::")
|
53
|
+
else
|
54
|
+
return nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def extractClassNameAndBody file
|
59
|
+
class_regex = /\/\/=\sSCRIPTABLE.*(\/\/=\sSCRIPTABLE\sBASES.*$|\s*)^(?!enum)\s*class\s+([a-zA-Z]+)[^;]*$.*\/\/=\s*BEGIN\s*SCRIPTABLE(.*)\/\/=\s*END\s*SCRIPTABLE.*?}/m
|
60
|
+
matches = class_regex.match(file)
|
61
|
+
if matches != nil
|
62
|
+
return matches.captures[1], matches.captures[2]
|
63
|
+
else
|
64
|
+
return nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def extractBaseClasses file
|
69
|
+
base_class_regex = /\/\/=\s*SCRIPTABLE\s*BASES(.*)$/
|
70
|
+
|
71
|
+
matches = base_class_regex.match(file)
|
72
|
+
|
73
|
+
if matches != nil
|
74
|
+
base_classes = matches.captures[0].split(" ").collect {|base| base.strip }
|
75
|
+
return base_classes
|
76
|
+
else
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def extractMethods text, full_text
|
82
|
+
methods = {}
|
83
|
+
text = text.split "\n"
|
84
|
+
|
85
|
+
function_regex = /([^:]*?)?\s+(\w*?)\((.*?),?\)\s*.*$/
|
86
|
+
|
87
|
+
template_types = []
|
88
|
+
text.each do |line|
|
89
|
+
matches = function_regex.match(line)
|
90
|
+
if !line.include?("= delete") && matches != nil
|
91
|
+
type = matches.captures[0].strip
|
92
|
+
name = matches.captures[1].strip
|
93
|
+
args = matches.captures[2].strip
|
94
|
+
overloaded = full_text.scan(/\s#{Regexp.quote(name)}\(/).count > 1
|
95
|
+
static = line.include?("static ")
|
96
|
+
|
97
|
+
|
98
|
+
arg_list = matches.captures[2].split(",").map { |a| a.split(/\s=/)[0] }
|
99
|
+
if(methods[name] == nil)
|
100
|
+
methods[name] = [[type, arg_list, overloaded, static]]
|
101
|
+
else
|
102
|
+
methods[name] << [type, arg_list, overloaded, static]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
return methods
|
107
|
+
end
|
108
|
+
|
109
|
+
def extractEnums file_text
|
110
|
+
enums = {}
|
111
|
+
|
112
|
+
scriptable_enum_regex = /\s*\/\/=\s*SCRIPTABLE\s*ENUM\s+(\/\*.*?\*\/)\s*\senum\s*[clas]*\s+(\w+)(\W*|\s*:\s*[a-zA-Z ]+){(.*?)};/m
|
113
|
+
|
114
|
+
class_regex = /^(?!enum)\s*class\s+([a-zA-Z]+).*/
|
115
|
+
|
116
|
+
matches = file_text.scan(scriptable_enum_regex)
|
117
|
+
class_matches = class_regex.match(file_text)
|
118
|
+
|
119
|
+
if matches != []
|
120
|
+
matches.each do |match|
|
121
|
+
name = match[1]
|
122
|
+
|
123
|
+
if class_matches != nil && file_text.index(class_matches[0]) < file_text.index(/\/\/=\s*SCRIPTABLE\s*ENUM\s*/)
|
124
|
+
name = class_matches.captures[0] + "::" + name
|
125
|
+
end
|
126
|
+
|
127
|
+
args = match[3].split(",").collect {|val| val.strip }
|
128
|
+
|
129
|
+
enums[name] = args
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
return enums
|
134
|
+
end
|
135
|
+
|
136
|
+
def generateGetModule class_name, metadata, base_classes
|
137
|
+
constructors = []
|
138
|
+
methods = []
|
139
|
+
|
140
|
+
metadata.each do |func_name, func_meta|
|
141
|
+
|
142
|
+
func_meta.each do |overload|
|
143
|
+
args = overload[1].join(", ")
|
144
|
+
#NO RETURN TYPE
|
145
|
+
if overload[0].empty?
|
146
|
+
constructors.push "chaiscript::constructor<#{class_name}(#{args})>(),"
|
147
|
+
#RETURN TYPE
|
148
|
+
else
|
149
|
+
overload[0].slice!("static ")
|
150
|
+
if overload[2] == false
|
151
|
+
methods.push "chaiscript::fun(&#{class_name}::#{func_name}), \"#{overload[3]?class_name + "_" : ""}#{func_name}\""
|
152
|
+
else
|
153
|
+
methods.push "chaiscript::fun([](#{class_name}& c#{args.length > 0 ? ", " + args : ""}) { c.#{func_name}(#{args.length > 0 ? (args.split(", ").map { |a| a.split(" ")[-1]}).join(", ") : ""}); }), \"#{func_name}\""
|
154
|
+
#methods.push "chaiscript::fun<#{overload[0]}, #{class_name}#{args.length > 0 ? ", " + args : ""}>(&#{class_name}::#{func_name}), \"#{func_name}\""
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
get_module = %?chaiscript::ModulePtr get#{class_name}Module() {
|
161
|
+
chaiscript::ModulePtr module = std::make_shared<chaiscript::Module>();
|
162
|
+
|
163
|
+
chaiscript::utility::add_class<#{class_name}>(*module, std::string("#{class_name}"),
|
164
|
+
?
|
165
|
+
|
166
|
+
get_module += "{\n"
|
167
|
+
constructors.each do |c|
|
168
|
+
get_module += c + "\n"
|
169
|
+
end
|
170
|
+
|
171
|
+
get_module += "},\n"
|
172
|
+
|
173
|
+
get_module += "{\n"
|
174
|
+
methods.each do |m|
|
175
|
+
get_module += "{" + m + "},\n"
|
176
|
+
end
|
177
|
+
|
178
|
+
get_module.chomp! ","
|
179
|
+
|
180
|
+
|
181
|
+
get_module += "});\n"
|
182
|
+
|
183
|
+
if base_classes != nil
|
184
|
+
base_classes.each do |b|
|
185
|
+
get_module += " module->add(chaiscript::base_class<#{b}, #{class_name}>());\n"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
get_module += "return module;\n"
|
189
|
+
get_module += "}\n"
|
190
|
+
|
191
|
+
return get_module, "get#{class_name}Module()"
|
192
|
+
end
|
193
|
+
|
194
|
+
def generateEnumModule enum_name, enum_contents
|
195
|
+
get_module = %?chaiscript::ModulePtr get#{enum_name.split("::").join("")}Module() {
|
196
|
+
chaiscript::ModulePtr module = std::make_shared<chaiscript::Module>();
|
197
|
+
std::vector<std::pair<unsigned int, std::string>> vec = {?
|
198
|
+
|
199
|
+
enum_contents.each do |c|
|
200
|
+
get_module += "{ #{enum_name.split('::').size > 1 ? enum_name.split("::")[0] + "::" : ""}#{c}, \"#{enum_name.split("::").join("_")}_#{c}\" },\n"
|
201
|
+
end
|
202
|
+
|
203
|
+
get_module += "};\n"
|
204
|
+
|
205
|
+
get_module += "chaiscript::utility::add_class<#{enum_name}>(*module, std::string(\"#{enum_name.split("::").join("_")}\"),\n"
|
206
|
+
get_module += "vec);\n"
|
207
|
+
|
208
|
+
get_module += "return module;\n"
|
209
|
+
get_module += "}\n"
|
210
|
+
|
211
|
+
return get_module, "get#{enum_name.split("::").join("")}Module()"
|
212
|
+
end
|
213
|
+
|
214
|
+
def getAllBases klass, names_to_bases
|
215
|
+
bases = names_to_bases[klass]
|
216
|
+
|
217
|
+
if bases != nil
|
218
|
+
bases.each do |base|
|
219
|
+
next_bases = getAllBases(base, names_to_bases)
|
220
|
+
if next_bases != nil
|
221
|
+
bases += getAllBases(base, names_to_bases)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
return bases
|
227
|
+
end
|
228
|
+
|
229
|
+
def run src_path, dst_path
|
230
|
+
puts "Running nymph-generate on path #{src_path}"
|
231
|
+
files = grabFiles(src_path + "/")
|
232
|
+
|
233
|
+
culled_files, culled_filenames = cullNonScriptableFiles(files)
|
234
|
+
|
235
|
+
class_names_to_bodies = {}
|
236
|
+
class_names_to_file_text = {}
|
237
|
+
class_names_to_filenames = {}
|
238
|
+
class_names_to_base_classes = {}
|
239
|
+
namespaces = []
|
240
|
+
enums = {}
|
241
|
+
enum_filenames = []
|
242
|
+
|
243
|
+
culled_files.zip(culled_filenames).each do |file, filename|
|
244
|
+
class_name, body = extractClassNameAndBody(file)
|
245
|
+
namespace = extractNamespace(file)
|
246
|
+
bases = extractBaseClasses(file)
|
247
|
+
|
248
|
+
ems = extractEnums(file)
|
249
|
+
if(ems != {})
|
250
|
+
enums.merge! ems
|
251
|
+
enum_filenames << filename
|
252
|
+
end
|
253
|
+
|
254
|
+
if(namespace != nil && namespaces.count(namespace) == 0)
|
255
|
+
namespaces << namespace
|
256
|
+
end
|
257
|
+
|
258
|
+
if(class_name != nil)
|
259
|
+
class_names_to_bodies[class_name] = body
|
260
|
+
class_names_to_file_text[class_name] = file
|
261
|
+
class_names_to_filenames[class_name] = filename
|
262
|
+
class_names_to_base_classes[class_name] = bases
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
#cascade up the bases
|
267
|
+
ctb = class_names_to_base_classes.clone
|
268
|
+
|
269
|
+
ctb.each do |klass, bases|
|
270
|
+
if bases != nil
|
271
|
+
bases.each do |base|
|
272
|
+
if ctb[base] != nil
|
273
|
+
class_names_to_base_classes[klass] += getAllBases(base, ctb)
|
274
|
+
class_names_to_base_classes[klass].uniq!
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
classes = {}
|
281
|
+
|
282
|
+
class_names_to_bodies.each_pair do |key, value|
|
283
|
+
classes[key] = extractMethods(value, class_names_to_file_text[key])
|
284
|
+
end
|
285
|
+
|
286
|
+
func_def_file = %?#ifndef GENERATED_REGISTRATIONS_H
|
287
|
+
#define GENERATED_REGISTRATIONS_H
|
288
|
+
//THIS FILE WAS GENERATED BY nymph-generate
|
289
|
+
//DO NOT EDIT IT AS IT WILL BE OVERWRITTEN WHEN nymph-generate IS RUN AGAIN
|
290
|
+
?
|
291
|
+
|
292
|
+
filenames = class_names_to_filenames.values | enum_filenames
|
293
|
+
|
294
|
+
func_def_file += "#include <chaiscript/utility/utility.hpp>\n"
|
295
|
+
func_def_file += "#include <vector>\n#include <map>\n"
|
296
|
+
filenames.each do |fn|
|
297
|
+
fn.slice! "./src/"
|
298
|
+
func_def_file += "#include \"#{fn}\"\n"
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
func_def_file += "namespace generated {\n"
|
303
|
+
|
304
|
+
namespaces.each do |n|
|
305
|
+
func_def_file += " using namespace #{n};\n"
|
306
|
+
end
|
307
|
+
|
308
|
+
func_calls = []
|
309
|
+
|
310
|
+
enums.each_pair do |name, vals|
|
311
|
+
mod, func_name = generateEnumModule(name, vals)
|
312
|
+
|
313
|
+
func_def_file += "\n#{mod}\n"
|
314
|
+
func_calls << func_name
|
315
|
+
end
|
316
|
+
|
317
|
+
classes.each_pair do |name, meta|
|
318
|
+
mod, func_name = generateGetModule(name, meta, class_names_to_base_classes[name])
|
319
|
+
|
320
|
+
func_def_file += "\n#{mod}\n"
|
321
|
+
func_calls << func_name
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
func_def_file += "void registerModules(std::shared_ptr<chaiscript::ChaiScript> chai) {\n"
|
326
|
+
|
327
|
+
func_calls.each do |f|
|
328
|
+
func_def_file += "chai->add(#{f});\n"
|
329
|
+
end
|
330
|
+
|
331
|
+
func_def_file += "}\n"
|
332
|
+
func_def_file += "}\n"
|
333
|
+
func_def_file += "#endif"
|
334
|
+
|
335
|
+
if(!Dir.exists? dst_path)
|
336
|
+
Dir.mkdir(dst_path)
|
337
|
+
end
|
338
|
+
|
339
|
+
puts "Writing #{dst_path}/generated_registrations.h"
|
340
|
+
File.open("#{dst_path}/generated_registrations.h", "w") { |f| f.write(func_def_file) }
|
341
|
+
puts "Wrote #{`cat #{dst_path}/generated_registrations.h | wc -l`.chomp!.strip!} lines!"
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nymph/generate/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nymph-generate"
|
8
|
+
spec.version = Nymph::Generate::VERSION
|
9
|
+
spec.authors = ["Adaleigh Martin"]
|
10
|
+
spec.email = ["adaleigh.martin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This is a Ruby Gem called nymph-generate to be used alongside the Nymph Game Engine}
|
13
|
+
spec.description = %q{nymph-generate is to be used alongside the Nymph Game Engine for generating Chaiscript modules for specified C++ classes and methods.}
|
14
|
+
spec.homepage = "https://sainteos.github.io/nymph-game-engine"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "bin"
|
20
|
+
spec.executables << "nymph-generate"
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nymph-generate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adaleigh Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: nymph-generate is to be used alongside the Nymph Game Engine for generating
|
42
|
+
Chaiscript modules for specified C++ classes and methods.
|
43
|
+
email:
|
44
|
+
- adaleigh.martin@gmail.com
|
45
|
+
executables:
|
46
|
+
- nymph-generate
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/nymph-generate
|
57
|
+
- bin/setup
|
58
|
+
- lib/nymph/generate.rb
|
59
|
+
- lib/nymph/generate/generator.rb
|
60
|
+
- lib/nymph/generate/version.rb
|
61
|
+
- nymph-generate.gemspec
|
62
|
+
homepage: https://sainteos.github.io/nymph-game-engine
|
63
|
+
licenses: []
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.6.14
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: This is a Ruby Gem called nymph-generate to be used alongside the Nymph Game
|
85
|
+
Engine
|
86
|
+
test_files: []
|