Class DL::Types
In: dl/types.rb
Parent: Object

Constants

TYPES = [ # FORMAT: # ["alias name", # "type name", encoding_method, decoding_method, for function prototypes # "type name", encoding_method, decoding_method] for structures (not implemented) # for Windows ["DWORD", "unsigned long", nil, nil, "unsigned long", nil, nil], ["PDWORD", "unsigned long *", nil, nil, "unsigned long *", nil, nil], ["WORD", "unsigned short", nil, nil, "unsigned short", nil, nil], ["PWORD", "unsigned int *", nil, nil, "unsigned int *", nil, nil], ["BYTE", "unsigned char", nil, nil, "unsigned char", nil, nil], ["PBYTE", "unsigned char *", nil, nil, "unsigned char *", nil, nil], ["BOOL", "ibool", nil, nil, "ibool", nil, nil], ["ATOM", "int", nil, nil, "int", nil, nil], ["BYTE", "unsigned char", nil, nil, "unsigned char", nil, nil], ["PBYTE", "unsigned char *", nil, nil, "unsigned char *", nil, nil], ["UINT", "unsigned int", nil, nil, "unsigned int", nil, nil], ["ULONG", "unsigned long", nil, nil, "unsigned long", nil, nil], ["UCHAR", "unsigned char", nil, nil, "unsigned char", nil, nil], ["HANDLE", "unsigned long", nil, nil, "unsigned long", nil, nil], ["PHANDLE","void*", nil, nil, "void*", nil, nil], ["PVOID", "void*", nil, nil, "void*", nil, nil], ["LPCSTR", "char*", nil, nil, "char*", nil, nil], ["HDC", "unsigned int", nil, nil, "unsigned int", nil, nil], ["HWND", "unsigned int", nil, nil, "unsigned int", nil, nil], # Others ["uint", "unsigned int", nil, nil, "unsigned int", nil, nil], ["u_int", "unsigned int", nil, nil, "unsigned int", nil, nil], ["ulong", "unsigned long", nil, nil, "unsigned long", nil, nil], ["u_long", "unsigned long", nil, nil, "unsigned long", nil, nil], # DL::Importable primitive types ["ibool", "I", proc{|v| v ? 1 : 0}, proc{|v| (v != 0) ? true : false}, "I", proc{|v| v ? 1 : 0 }, proc{|v| (v != 0) ? true : false} ], ["cbool", "C", proc{|v| v ? 1 : 0}, proc{|v| (v != 0) ? true : false}, "C", proc{|v,len| v ? 1 : 0}, proc{|v,len| (v != 0) ? true : false}], ["lbool", "L", proc{|v| v ? 1 : 0}, proc{|v| (v != 0) ? true : false}, "L", proc{|v,len| v ? 1 : 0}, proc{|v,len| (v != 0) ? true : false}], ["unsigned char", "C", proc{|v| [v].pack("C").unpack("c")[0]}, proc{|v| [v].pack("c").unpack("C")[0]}, "C", proc{|v| [v].pack("C").unpack("c")[0]}, proc{|v| [v].pack("c").unpack("C")[0]}], ["unsigned short", "H", proc{|v| [v].pack("S").unpack("s")[0]}, proc{|v| [v].pack("s").unpack("S")[0]}, "H", proc{|v| [v].pack("S").unpack("s")[0]}, proc{|v| [v].pack("s").unpack("S")[0]}], ["unsigned int", "I", proc{|v| [v].pack("I").unpack("i")[0]}, proc{|v| [v].pack("i").unpack("I")[0]}, "I", proc{|v| [v].pack("I").unpack("i")[0]}, proc{|v| [v].pack("i").unpack("I")[0]}], ["unsigned long", "L", proc{|v| [v].pack("L").unpack("l")[0]}, proc{|v| [v].pack("l").unpack("L")[0]}, "L", proc{|v| [v].pack("L").unpack("l")[0]}, proc{|v| [v].pack("l").unpack("L")[0]}], ["unsigned char ref", "c", proc{|v| [v].pack("C").unpack("c")[0]}, proc{|v| [v].pack("c").unpack("C")[0]}, nil, nil, nil], ["unsigned int ref", "i", proc{|v| [v].pack("I").unpack("i")[0]}, proc{|v| [v].pack("i").unpack("I")[0]}, nil, nil, nil], ["unsigned long ref", "l", proc{|v| [v].pack("L").unpack("l")[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], ]

Public Class methods

[Source]

     # File dl/types.rb, line 164
164:     def initialize
165:       init_types()
166:     end

Public Instance methods

[Source]

     # File dl/types.rb, line 176
176:     def encode_argument_type(alias_type)
177:       proc_encode = nil
178:       proc_decode = nil
179:       @TYDEFS.each{|aty,ty,enc,dec,_,_,_|
180:         if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) )
181:           alias_type = alias_type.gsub(aty,ty) if ty
182:           alias_type.strip! if alias_type
183:           if( proc_encode )
184:             if( enc )
185:               conv1 = proc_encode
186:               proc_encode = proc{|v| enc.call(conv1.call(v))}
187:             end
188:           else
189:             if( enc )
190:               proc_encode = enc
191:             end
192:           end
193:           if( proc_decode )
194:             if( dec )
195:               conv2 = proc_decode
196:               proc_decode = proc{|v| dec.call(conv2.call(v))}
197:             end
198:           else
199:             if( dec )
200:               proc_decode = dec
201:             end
202:           end
203:         end
204:       }
205:       return [alias_type, proc_encode, proc_decode]
206:     end

[Source]

     # File dl/types.rb, line 208
208:     def encode_return_type(ty)
209:       ty, enc, dec = encode_argument_type(ty)
210:       return [ty, enc, dec]
211:     end

[Source]

     # File dl/types.rb, line 213
213:     def encode_struct_type(alias_type)
214:       proc_encode = nil
215:       proc_decode = nil
216:       @TYDEFS.each{|aty,_,_,_,ty,enc,dec|
217:         if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) )
218:           alias_type = alias_type.gsub(aty,ty) if ty
219:           alias_type.strip! if alias_type
220:           if( proc_encode )
221:             if( enc )
222:               conv1 = proc_encode
223:               proc_encode = proc{|v| enc.call(conv1.call(v))}
224:             end
225:           else
226:             if( enc )
227:               proc_encode = enc
228:             end
229:           end
230:           if( proc_decode )
231:             if( dec )
232:               conv2 = proc_decode
233:               proc_decode = proc{|v| dec.call(conv2.call(v))}
234:             end
235:           else
236:             if( dec )
237:               proc_decode = dec
238:             end
239:           end
240:         end
241:       }
242:       return [alias_type, proc_encode, proc_decode]
243:     end

[Source]

     # File dl/types.rb, line 172
172:     def init_types
173:       @TYDEFS = TYPES.dup
174:     end

[Source]

     # File dl/types.rb, line 168
168:     def typealias(ty1, ty2, enc=nil, dec=nil, ty3=nil, senc=nil, sdec=nil)
169:       @TYDEFS.unshift([ty1, ty2, enc, dec, ty3, senc, sdec])
170:     end

Search

Google

Ruby API Docs

Links