Class: DL::Types
- Inherits:
-
Object
- Object
- DL::Types
- Defined in:
- lib/dl/types.rb
Constant Summary collapse
- TYPES =
[0]}, proc{|v| [v].pack("l").unpack("L")[0]}, nil, nil, nil], ["char ref", "c", nil, nil, nil, nil, nil], ["short ref", "h", nil, nil, nil, nil, nil], ["int ref", "i", nil, nil, nil, nil, nil], ["long ref", "l", nil, nil, nil, nil, nil], ["float ref", "f", nil, nil, nil, nil, nil], ["double ref","d", nil, nil, nil, nil, nil], ["char", "C", nil, nil, "C", nil, nil], ["short", "H", nil, nil, "H", nil, nil], ["int", "I", nil, nil, "I", nil, nil], ["long", "L", nil, nil, "L", nil, nil], ["float", "F", nil, nil, "F", nil, nil], ["double", "D", nil, nil, "D", nil, nil], [/^char\s*\*$/,"s",nil, nil, "S",nil, nil], [/^const char\s*\*$/,"S",nil, nil, "S",nil, nil], [/^.+\*$/, "P", nil, nil, "P", nil, nil], [/^.+\[\]$/, "a", nil, nil, "a", nil, nil], ["void", "0", nil, nil, nil, nil, nil], ]
Instance Method Summary collapse
- #encode_argument_type(alias_type) ⇒ Object
- #encode_return_type(ty) ⇒ Object
- #encode_struct_type(alias_type) ⇒ Object
- #init_types ⇒ Object
-
#initialize ⇒ Types
constructor
A new instance of Types.
- #typealias(ty1, ty2, enc = nil, dec = nil, ty3 = nil, senc = nil, sdec = nil) ⇒ Object
Constructor Details
#initialize ⇒ Types
Returns a new instance of Types.
164 165 166 |
# File 'lib/dl/types.rb', line 164 def initialize init_types() end |
Instance Method Details
#encode_argument_type(alias_type) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/dl/types.rb', line 176 def encode_argument_type(alias_type) proc_encode = nil proc_decode = nil @TYDEFS.each{|aty,ty,enc,dec,_,_,_| if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) ) alias_type = alias_type.gsub(aty,ty) if ty alias_type.strip! if alias_type if( proc_encode ) if( enc ) conv1 = proc_encode proc_encode = proc{|v| enc.call(conv1.call(v))} end else if( enc ) proc_encode = enc end end if( proc_decode ) if( dec ) conv2 = proc_decode proc_decode = proc{|v| dec.call(conv2.call(v))} end else if( dec ) proc_decode = dec end end end } return [alias_type, proc_encode, proc_decode] end |
#encode_return_type(ty) ⇒ Object
208 209 210 211 |
# File 'lib/dl/types.rb', line 208 def encode_return_type(ty) ty, enc, dec = encode_argument_type(ty) return [ty, enc, dec] end |
#encode_struct_type(alias_type) ⇒ Object
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 238 239 240 241 242 243 |
# File 'lib/dl/types.rb', line 213 def encode_struct_type(alias_type) proc_encode = nil proc_decode = nil @TYDEFS.each{|aty,_,_,_,ty,enc,dec| if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) ) alias_type = alias_type.gsub(aty,ty) if ty alias_type.strip! if alias_type if( proc_encode ) if( enc ) conv1 = proc_encode proc_encode = proc{|v| enc.call(conv1.call(v))} end else if( enc ) proc_encode = enc end end if( proc_decode ) if( dec ) conv2 = proc_decode proc_decode = proc{|v| dec.call(conv2.call(v))} end else if( dec ) proc_decode = dec end end end } return [alias_type, proc_encode, proc_decode] end |
#init_types ⇒ Object
172 173 174 |
# File 'lib/dl/types.rb', line 172 def init_types @TYDEFS = TYPES.dup end |
#typealias(ty1, ty2, enc = nil, dec = nil, ty3 = nil, senc = nil, sdec = nil) ⇒ Object
168 169 170 |
# File 'lib/dl/types.rb', line 168 def typealias(ty1, ty2, enc=nil, dec=nil, ty3=nil, senc=nil, sdec=nil) @TYDEFS.unshift([ty1, ty2, enc, dec, ty3, senc, sdec]) end |