1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Add ext/dl/lib/dl/types.rb.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ttate 2002-04-03 15:43:12 +00:00
parent 74b4c81396
commit b5856f738a
3 changed files with 94 additions and 68 deletions

View file

@ -1,3 +1,7 @@
Wed Apr 3 15:37:24 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp>
* ext/dl: Add dl/types.rb.
Wed Apr 3 20:42:34 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp>
* ext/dl: Merge Nakada's patch.

View file

@ -1,6 +1,7 @@
# -*- ruby -*-
require 'dl'
require 'dl/types'
module DL
module Importable
@ -153,74 +154,7 @@ module DL
end
def init_type
@TYDEFS = [
# for Windows
["DWORD", "unsigned long", nil, nil],
["PDWORD", "unsigned long *", nil, nil],
["WORD", "unsigned int", nil, nil],
["PWORD", "unsigned int *", nil, nil],
["BOOL", "ibool", nil, nil],
["ATOM", "int", nil, nil],
["BYTE", "unsigned char", nil, nil],
["PBYTE", "unsigned char *", nil, nil],
["UINT", "unsigned int", nil, nil],
["ULONG", "unsigned long", nil, nil],
["UCHAR", "unsigned char", nil, nil],
["HANDLE", "unsigned long", nil, nil],
["PHANDLE","void*", nil, nil],
["PVOID", "void*", nil, nil],
["LPCSTR", "char*", nil, nil],
# Others
["uint", "unsigned int", nil, nil],
["u_int", "unsigned int", nil, nil],
["ulong", "unsigned long", nil, nil],
["u_long", "unsigned long", nil, nil],
# DL::Importable primitive types
["ibool", "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}],
["lbool", "L",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false}],
["unsigned char", "I",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]}],
["unsigned int", "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]}],
["unsigned char ref", "i",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]}],
["unsigned int ref", "i",
proc{|v| [v].pack("I").unpack("i")[0]},
proc{|v| [v].pack("i").unpack("I")[0]}],
["unsigned long ref", "l",
proc{|v| [v].pack("L").unpack("l")[0]},
proc{|v| [v].pack("l").unpack("L")[0]}],
["char ref", "c", nil, nil],
["short ref", "h", nil, nil],
["int ref", "i", nil, nil],
["long ref", "l", nil, nil],
["float ref", "f", nil, nil],
["double ref","d", nil, nil],
["char", "C", nil, nil],
["short", "H", nil, nil],
["int", "I", nil, nil],
["long", "L", nil, nil],
["float", "F", nil, nil],
["double", "D", nil, nil],
[/.+\*/, "P", nil, nil],
[/.+\[\]/, "a", nil, nil],
["void", "0", nil, nil],
]
@TYDEFS = TYPES.collect{|ty| ty[0..3]}
end
end # end of Internal
include Internal

88
ext/dl/lib/dl/types.rb Normal file
View file

@ -0,0 +1,88 @@
# -*- ruby -*-
require 'dl'
module DL
TYPES = [
# FORMAT:
# ["alias name", "type name",
# encoding_method, decoding_method, for function prototypes
# encoding_method, decoding_method] for structures (not implemented)
# for Windows
["DWORD", "unsigned long", nil, nil, nil, nil],
["PDWORD", "unsigned long *", nil, nil, nil, nil],
["WORD", "unsigned int", nil, nil, nil, nil],
["PWORD", "unsigned int *", nil, nil, nil, nil],
["BOOL", "ibool", nil, nil, nil, nil],
["ATOM", "int", nil, nil, nil, nil],
["BYTE", "unsigned char", nil, nil, nil, nil],
["PBYTE", "unsigned char *", nil, nil, nil, nil],
["UINT", "unsigned int", nil, nil, nil, nil],
["ULONG", "unsigned long", nil, nil, nil, nil],
["UCHAR", "unsigned char", nil, nil, nil, nil],
["HANDLE", "unsigned long", nil, nil, nil, nil],
["PHANDLE","void*", nil, nil, nil, nil],
["PVOID", "void*", nil, nil, nil, nil],
["LPCSTR", "char*", nil, nil, nil, nil],
# Others
["uint", "unsigned int", nil, nil, nil, nil],
["u_int", "unsigned int", nil, nil, nil, nil],
["ulong", "unsigned long", nil, nil, nil, nil],
["u_long", "unsigned long", nil, nil, nil, nil],
# DL::Importable primitive types
["ibool", "I",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
nil, nil],
["cbool", "C",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
nil, nil],
["lbool", "L",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
nil, nil],
["unsigned char", "I",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]},
nil, nil],
["unsigned int", "I",
proc{|v| [v].pack("I").unpack("i")[0]},
proc{|v| [v].pack("i").unpack("I")[0]},
nil, nil],
["unsigned long", "L",
proc{|v| [v].pack("L").unpack("l")[0]},
proc{|v| [v].pack("l").unpack("L")[0]},
nil, nil],
["unsigned char ref", "i",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]},
nil, nil],
["unsigned int ref", "i",
proc{|v| [v].pack("I").unpack("i")[0]},
proc{|v| [v].pack("i").unpack("I")[0]},
nil, nil],
["unsigned long ref", "l",
proc{|v| [v].pack("L").unpack("l")[0]},
proc{|v| [v].pack("l").unpack("L")[0]},
nil, nil],
["char ref", "c", nil, nil, nil, nil],
["short ref", "h", nil, nil, nil, nil],
["int ref", "i", nil, nil, nil, nil],
["long ref", "l", nil, nil, nil, nil],
["float ref", "f", nil, nil, nil, nil],
["double ref","d", nil, nil, nil, nil],
["char", "C", nil, nil, nil, nil],
["short", "H", nil, nil, nil, nil],
["int", "I", nil, nil, nil, nil],
["long", "L", nil, nil, nil, nil],
["float", "F", nil, nil, nil, nil],
["double", "D", nil, nil, nil, nil],
[/.+\*/, "P", nil, nil, nil, nil],
[/.+\[\]/, "a", nil, nil, nil, nil],
["void", "0", nil, nil, nil, nil],
]
end