Class: Hsss::CWhole
Constant Summary
collapse
- EXT =
"lua"
Instance Attribute Summary
Attributes inherited from COutput
#all_hashes_string_name, #count_macro_name, #count_name, #hashes_struct, #iter_macro_name, #names_struct, #row_struct_name, #scripts_struct, #struct_name
Instance Method Summary
collapse
Methods inherited from COutput
#all_hashes_string_macro, #cased_prefix, #check_script, #count_macro, #cquote
Constructor Details
#initialize(files, opt = {}) ⇒ CWhole
Returns a new instance of CWhole.
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
# File 'lib/hsss.rb', line 213
def initialize(files, opt={})
super
@headf= <<-EOS.gsub(/^ {8}/, '')
// don't edit this please, it was auto-generated by hsss
// https://github.com/slact/hsss
typedef struct {
char *name;#{@include_hash ? "\n char *hash;" : ""}
char *script;
} #{row_struct_name};
typedef struct {
%s
} #{struct_name};
EOS
@cout= <<-EOS.gsub(/^ {8}/, '')
#{@headf}
#{@static}#{struct_name} #{scripts_struct} = {
%s
};
EOS
end
|
Instance Method Details
#failed? ⇒ Boolean
296
297
298
|
# File 'lib/hsss.rb', line 296
def failed?
@failed
end
|
#iter_macro ⇒ Object
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/hsss.rb', line 285
def iter_macro
if @include_iter_macro
macro = []
macro << "#define #{iter_macro_name}(script) \\"
macro << "for((script)=(#{row_struct_name} *)&#{scripts_struct}; (script) < (#{row_struct_name} *)(&#{scripts_struct} + 1); (script)++) "
macro.join("\n")
else
""
end
end
|
#script_name_line(name) ⇒ Object
239
240
241
|
# File 'lib/hsss.rb', line 239
def script_name_line(name)
"#{row_struct_name} #{name};"
end
|
#script_string(name, script) ⇒ Object
242
243
244
|
# File 'lib/hsss.rb', line 242
def script_string(name, script)
cquote(script, " ")
end
|
#to_s ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/hsss.rb', line 245
def to_s
out = ""
if @scripts.count > 0
scrapts=[]
for i in 0...@scripts.count do
scrapts<< " {\"#{@name_table[i]}\", #{@include_hash ? "\"#{@hashed_table[i]}\"," : ""}\n#{@script_table[i]}}"
end
else
scripties = nil
end
if @header_only
if @header_guard
out << "#ifndef #{@header_guard}\n"
out << "#define #{@header_guard}\n"
end
out << sprintf(@headf, @struct.join("\n"))
out << "extern #{@static}#{struct_name} #{scripts_struct};\n"
out << "extern const int #{@count_name};\n" if @include_count
out << all_hashes_string_macro
out << count_macro
out << iter_macro
if @header_guard
out << "\n#endif //#{@header_guard}\n"
end
elsif @data_only
out << "#{@static}#{struct_name} #{scripts_struct} = {\n"
out << "#{scrapts.join(",\n\n")}\n"
out << "};\n"
out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
else
out << sprintf(@cout, (@struct || []).join("\n"), (scrapts || []).join(",\n\n"))
out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
out << all_hashes_string_macro
out << count_macro
out << iter_macro
end
out
end
|