diff --git a/lib/fiddle/cparser.rb b/lib/fiddle/cparser.rb index 8a269393..69373e89 100644 --- a/lib/fiddle/cparser.rb +++ b/lib/fiddle/cparser.rb @@ -108,16 +108,15 @@ def parse_struct_signature(signature, tymap=nil) # def parse_signature(signature, tymap=nil) tymap ||= {} - case compact(signature) - when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ - func, args = $1, $2 - return [func, TYPE_VOIDP, split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] - when /^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/ - ret, func, args = $1.strip, $2, $3 - return [func, parse_ctype(ret, tymap), split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] - else - raise(RuntimeError,"can't parse the function prototype: #{signature}") - end + ctype, func, args = case compact(signature) + when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ + [TYPE_VOIDP, $1, $2] + when /^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/ + [parse_ctype($1.strip, tymap), $2, $3] + else + raise("can't parse the function prototype: #{signature}") + end + [func, ctype, split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] end # Given a String of C type +ty+, returns the corresponding Fiddle constant.