Mercurial > projects > dstep
diff scripts/dgen.rb @ 4:5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 05 Jul 2009 21:52:04 +0200 |
parents | d0162d8ca0f2 |
children | 9e67a1122e85 |
line wrap: on
line diff
--- a/scripts/dgen.rb Sun Jul 05 20:54:42 2009 +0200 +++ b/scripts/dgen.rb Sun Jul 05 21:52:04 2009 +0200 @@ -182,7 +182,7 @@ # This Struct represents a C/Objective-C header HeaderFile = Struct.new(:name, :framework, :cftypes, :constants, :c_constants, :d_constants, :d_constants_static_this, :defines, - :enums, :functions, :c_functions, :function_wrappers, :imports, :path, :structs, :typedefs) do + :enums, :functions, :c_functions, :function_pointers, :function_wrappers, :imports, :path, :structs, :typedefs) do def initialize self.name = "" self.cftypes = [] @@ -192,6 +192,7 @@ self.framework = "" self.functions = [] self.c_functions = [] + self.function_pointers = [] self.function_wrappers = [] self.imports = [] self.path = "" @@ -248,6 +249,7 @@ header.enums = enums(file.enum) unless file.enum.nil? header.functions = functions(file.function) unless file.function.nil? header.c_functions = c_functions unless file.function.nil? + header.function_pointers = function_pointers(file.functionPointer) unless file.functionPointer.nil? header.function_wrappers = function_wrappers unless file.function.nil? header.imports = imports(file.import, file.name, framework.name) unless file.import.nil? header.structs = structs(file.struct) unless file.struct.nil? @@ -273,6 +275,7 @@ header.d_constants_static_this = d_constants_static_this unless file.constant.nil? header.enums = enums(file.enum) unless file.enum.nil? header.functions = functions(file.function) unless file.function.nil? + header.function_pointers = function_pointers(file.functionPointer) unless file.functionPointer.nil? header.c_functions = c_functions unless file.function.nil? header.function_wrappers = function_wrappers unless file.function.nil? header.imports = imports(file.import, file.name) unless file.import.nil? @@ -311,6 +314,7 @@ file << header.defines file << header.typedefs file << header.cftypes + file << header.function_pointers file << header.c_constants file << header.d_constants file << header.enums @@ -345,7 +349,7 @@ end file << header.function_wrappers - file << header.c_functions + file << header.c_functions end File.open(bindings_file_path, "w") do |file| @@ -377,6 +381,7 @@ file << header.defines file << header.typedefs file << header.cftypes + file << header.function_pointers file << header.c_constants file << header.d_constants file << header.enums @@ -790,9 +795,7 @@ return "" if args.nil? str = StringIO.new - if variadic - #p args - end + args.each do |arg| if method || arg.type != "@" @@ -802,7 +805,7 @@ end str << type - str << " " + str << " " unless arg.name.nil? str << get_identifier(arg["name"]) str << ", " end @@ -879,6 +882,27 @@ str.string end + def function_pointers (function_pointers) + return "" if function_pointers.length == 0 + + str = StringIO.new + + str << "extern (C)\n{".nl(false) + + function_pointers.each do |fp| + str << "alias ".indent + str << get_type(fp.returnValue[0].type, fp.returnValue[0].type64, fp.returnValue[0].declaredType) + str << " function (" + str << args(fp.arg, fp.variadic == "true") + str << ") " + str << get_identifier(fp.name).nl + end + + str << "}".nl(false).nl(false) + + str.string + end + def c_functions return "" if @c_functions.length == 0