File: pointer.rb

package info (click to toggle)
jruby 1.5.1-1%2Bdeb6u1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze-lts
  • size: 47,024 kB
  • ctags: 74,144
  • sloc: ruby: 398,155; java: 169,506; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (54 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module FFI
  class Pointer

      def write_string(str, len=nil)
        len = str.size unless len
        # Write the string data without NUL termination
        put_bytes(0, str)
      end
      def read_array_of_type(type, reader, length)
        ary = []
        size = FFI.type_size(type)
        tmp = self
        (length - 1).times {
          ary << tmp.send(reader)
          tmp += size
        }
        ary << tmp.send(reader)
        ary
      end

      def write_array_of_type(type, writer, ary)
        size = FFI.type_size(type)
        tmp = self
        (ary.length - 1).times do |i|
          tmp.send(writer, ary[i])
          tmp += size
        end
        tmp.send(writer, ary.last)
        self
      end
      def read_array_of_int(length)
        get_array_of_int32(0, length)
      end

      def write_array_of_int(ary)
        put_array_of_int32(0, ary)
      end

      def read_array_of_long(length)
        get_array_of_long(0, length)
      end

      def write_array_of_long(ary)
        put_array_of_long(0, ary)
      end

      def read_array_of_pointer(length)
        get_array_of_pointer(0, length)
      end
      def write_array_of_pointer(ary)
        put_array_of_pointer(0, ary)
      end
  end
end