diff options
Diffstat (limited to 'generate.rb')
| -rw-r--r-- | generate.rb | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/generate.rb b/generate.rb index 30ab22a..f94e0ec 100644 --- a/generate.rb +++ b/generate.rb @@ -35,6 +35,7 @@ includes = %{ #include <raylib.h> #include <mruby.h> #include <mruby/array.h> +#include <mruby/data.h> #include <mruby/class.h> #include <mruby/numeric.h> #include <mruby/string.h> @@ -44,6 +45,21 @@ includes = %{ defines = "" init_body = "" + +# convert types +# need to make this built in +# functionality(with scanner + generator) +glue.first.keys.each do |k| + rpart = k.rpartition(' ') + + #glue.first[ mappings[k] ] = glue.first.delete(k) if mappings[k] + if 'Texture2D' == rpart.first + glue.first["Texture #{rpart.last}"] = glue.first.delete(k) + elsif 'RenderTexture2D' == rpart.first + glue.first["RenderTexture #{rpart.last}"] = glue.first.delete(k) + end +end + # for displaying statistics glue.first.each do |func, params| if (func.rpartition(' ').first == 'void') && (params[0] == 'void') @@ -85,6 +101,13 @@ def debug_mark_binding(func, params) end end + +# generates structs +glue.last.each do |struct, params| + defines += Tplt.init_struct_wrapper(struct) + init_body += Tplt.init_class(struct, 'test') +end + # generates functions glue.first.each do |func, params| # func = function name with return type @@ -95,18 +118,13 @@ glue.first.each do |func, params| func_datatype = rpart.first func_name = rpart.last - # if phase 1 - if func_datatype == 'void' && params[0] == 'void' - body = Tplt.return_format(func, params) #"#{func_name}();\nreturn mrb_nil_value();" - #defines += 'PHASE 1\n' - defines += Tplt.function(func_name, body) - init_body += Tplt.init_module_function('test', Tplt.rubify_func_name(func_name), func_name, "MRB_ARGS_NONE()") + next if ['long', 'void *'].include? func_datatype - debug_mark_binding(func, params) - # if phase 2 - elsif (Tplt.non_struct_types.include? func_datatype) && (params[0] == 'void') - body = Tplt.return_format(func, params) - #defines += 'PHASE 2\n' + # if phase 1 or 2 + if (func_datatype == 'void' && params[0] == 'void') || ((Tplt.non_struct_types.include? func_datatype) && (params[0] == 'void')) + body = Tplt.return_format(func, params) + #defines += 'PHASE 1\n' + defines += "\n//#{func}" defines += Tplt.function(func_name, body) init_body += Tplt.init_module_function('test', Tplt.rubify_func_name(func_name), func_name, "MRB_ARGS_NONE()") @@ -121,11 +139,11 @@ glue.first.each do |func, params| end end if no_struct_param - if Tplt.non_struct_types.include? func.rpartition(' ').first + if true# Tplt.non_struct_types.include? func.rpartition(' ').first #$phase3[func] = params # --- - #body = '' - body = Tplt.return_format(func, params) + body = '' + #body = Tplt.return_format(func, params) init_var_body = '' init_array_body = '' unwrapped_kwargs = '' @@ -139,9 +157,25 @@ glue.first.each do |func, params| init_array_body += "mrb_intern_lit(mrb, \"#{temp_rpart.last}\"),\n" unwrapped_kwargs += Tplt.unwrap_kwarg(index, "#{temp_rpart.last} = #{Tplt.to_c(temp_rpart.first, "kw_values[#{index}]")};", nil, "#{temp_rpart.last} Argument Missing") end + + # if return isnt regular types, add struct to init + unless Tplt.non_struct_types.include? func_datatype + init_var_body += "#{func_datatype} *return_value = {0};\n" + end + body = Tplt.get_kwargs(params.length, init_var_body, init_array_body) body += unwrapped_kwargs - body += Tplt.return_format(func, params) + + # if return isnt regular types, use struct return format + if Tplt.non_struct_types.include? func_datatype + body += Tplt.return_format(func, params) + else + body += Tplt.get_module('Test') + body += Tplt.get_class(func_datatype, 'test') + body += Tplt.return_format_struct(func) + end + + defines += "\n//#{func}" defines += Tplt.function(func_name, body) init_body += Tplt.init_module_function('test', Tplt.rubify_func_name(func_name), func_name, "MRB_ARGS_OPT(1)") # opt stuff isnt correct, need to look at this again # --- @@ -177,3 +211,9 @@ result += "//Phase 5 Functions: #{$complete_phase5.length} / #{$phase5.length}\n puts result + +#$phase4.reverse_each do |key, elem| +# puts '---' +# puts key +# pp elem +#end |
