summaryrefslogtreecommitdiff
path: root/ext/fiddle/lib/fiddle/cparser.rb
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-28 02:08:39 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-28 02:08:39 +0000
commit4ed6a88b74be65894b580dba81e7b8e3e8b0c3ce (patch)
tree175e78cc10375e9091a6e712f4d1f51a42856608 /ext/fiddle/lib/fiddle/cparser.rb
parent0700a9113f94a82d786271bc44140691d47f6bac (diff)
* ext/fiddle/closure.c: Documentation for Fiddle
* ext/fiddle/lib/fiddle/import.rb: ditto * ext/fiddle/lib/fiddle/value.rb: ditto * ext/fiddle/lib/fiddle/pack.rb: ditto * ext/fiddle/lib/fiddle/cparser.rb: ditto * ext/fiddle/lib/fiddle/struct.rb: ditto * ext/fiddle/lib/fiddle/function.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/fiddle/lib/fiddle/cparser.rb')
-rw-r--r--ext/fiddle/lib/fiddle/cparser.rb40
1 files changed, 30 insertions, 10 deletions
diff --git a/ext/fiddle/lib/fiddle/cparser.rb b/ext/fiddle/lib/fiddle/cparser.rb
index ede88ae668..43fb184a12 100644
--- a/ext/fiddle/lib/fiddle/cparser.rb
+++ b/ext/fiddle/lib/fiddle/cparser.rb
@@ -1,12 +1,25 @@
module Fiddle
- # Methods for parsing C struct and C prototype signatures.
+ # A mixin that provides methods for parsing C struct and prototype signatures.
+ #
+ # == Example
+ # require 'fiddle/import'
+ #
+ # include Fiddle::CParser
+ # #=> Object
+ #
+ # parse_ctype('int increment(int)')
+ # #=> ["increment", Fiddle::TYPE_INT, [Fiddle::TYPE_INT]]
+ #
module CParser
# Parses a C struct's members
#
# Example:
#
+ # include Fiddle::CParser
+ # #=> Object
+ #
# parse_struct_signature(['int i', 'char c'])
- # => [[Fiddle::TYPE_INT, Fiddle::TYPE_CHAR], ["i", "c"]]
+ # #=> [[Fiddle::TYPE_INT, Fiddle::TYPE_CHAR], ["i", "c"]]
#
def parse_struct_signature(signature, tymap=nil)
if( signature.is_a?(String) )
@@ -45,13 +58,17 @@ module Fiddle
# Parses a C prototype signature
#
+ # If Hash +tymap+ is provided, the return value and the arguments from the
+ # +signature+ are expected to be keys, and the value will be the C type to
+ # be looked up.
+ #
# Example:
#
# include Fiddle::CParser
- # => Object
+ # #=> Object
#
# parse_signature('double sum(double, double)')
- # => ["sum", Fiddle::TYPE_DOUBLE, [Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]]
+ # #=> ["sum", Fiddle::TYPE_DOUBLE, [Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]]
#
def parse_signature(signature, tymap=nil)
tymap ||= {}
@@ -74,24 +91,27 @@ module Fiddle
end
end
- # Given a String of C type +ty+, return the corresponding DL constant.
+ # Given a String of C type +ty+, returns the corresponding Fiddle constant.
#
- # +ty+ can also accept an Array of C type Strings, and will returned in a
- # corresponding Array.
+ # +ty+ can also accept an Array of C type Strings, and will be returned in
+ # a corresponding Array.
#
# If Hash +tymap+ is provided, +ty+ is expected to be the key, and the
# value will be the C type to be looked up.
#
# Example:
#
+ # include Fiddle::CParser
+ # #=> Object
+ #
# parse_ctype('int')
- # => Fiddle::TYPE_INT
+ # #=> Fiddle::TYPE_INT
#
# parse_ctype('double')
- # => Fiddle::TYPE_DOUBLE
+ # #=> Fiddle::TYPE_DOUBLE
#
# parse_ctype('unsigned char')
- # => -Fiddle::TYPE_CHAR
+ # #=> -Fiddle::TYPE_CHAR
#
def parse_ctype(ty, tymap=nil)
tymap ||= {}