fiddley 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fiddley.rb +1 -1
- data/lib/fiddley/library.rb +17 -7
- data/lib/fiddley/memory_pointer.rb +11 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89adacb7382de9ea109dda5d0a9aa9a0126a3198
|
4
|
+
data.tar.gz: f8e12868b55cddad59d0981a01690d41b23888dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e455169f82ace8c779056efe3c6eda4f88ab6a5d13012a9d3bea5c59246876278e9cabccd73f72dab79e7151687a9af96493f7f97bc55bbcd45d922c8d8b829
|
7
|
+
data.tar.gz: 03bc837b03cf53ccbe543efe6432596a34e158646bf91894ac7282c392cb14401cddc8f7f3c9516ede054a6194891ed3cc7d347bc5f61fc36c503fad30dc034d
|
data/lib/fiddley.rb
CHANGED
data/lib/fiddley/library.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "fiddle/import"
|
2
|
+
require "fiddley/struct"
|
2
3
|
require "fiddley/utils"
|
3
4
|
|
4
5
|
module Fiddley
|
@@ -45,13 +46,12 @@ module Fiddley
|
|
45
46
|
cname = rname
|
46
47
|
end
|
47
48
|
extern "#{type2str(ret)} #{cname}(#{params.map{|e| type2str(e)}.join(', ')})", @convention
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
__send__(tname, *args).to_s
|
49
|
+
case ret
|
50
|
+
when :string
|
51
|
+
wrap_function(cname, &:to_s)
|
52
|
+
when :pointer
|
53
|
+
wrap_function(cname) do |result|
|
54
|
+
Fiddley::MemoryPointer.new(ret, result)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
if cname != rname
|
@@ -61,6 +61,16 @@ module Fiddley
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
private def wrap_function(cname, &blk)
|
65
|
+
tname = (cname.to_s + '+').to_sym
|
66
|
+
instance_eval <<-end
|
67
|
+
alias #{tname.inspect} #{cname.inspect}
|
68
|
+
end
|
69
|
+
define_singleton_method(cname) do |*args|
|
70
|
+
blk.call(__send__(tname, *args))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
64
74
|
case RUBY_PLATFORM
|
65
75
|
when /cygwin/
|
66
76
|
libprefix = "cyg"
|
@@ -10,8 +10,13 @@ module Fiddley
|
|
10
10
|
include Fiddley::Utils
|
11
11
|
|
12
12
|
def initialize(type, num = 1, clear = true)
|
13
|
-
|
14
|
-
|
13
|
+
if num.is_a?(Fiddle::Pointer)
|
14
|
+
@ptr = num
|
15
|
+
@size = @ptr.size
|
16
|
+
else
|
17
|
+
@size = type2size(type) * num
|
18
|
+
@ptr = Fiddle::Pointer.malloc(@size)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
attr_reader :size
|
@@ -90,12 +95,12 @@ module Fiddley
|
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
93
|
-
def put_bytes(offset, str, len =
|
94
|
-
@ptr[offset, len
|
98
|
+
def put_bytes(offset, str, idx = 0, len = str.bytesize - idx)
|
99
|
+
@ptr[offset, len] = str[idx, len]
|
95
100
|
end
|
96
101
|
|
97
|
-
def write_bytes(str, len = nil)
|
98
|
-
put_bytes(0, str, len)
|
102
|
+
def write_bytes(str, idx = 0, len = nil)
|
103
|
+
put_bytes(0, str, idx, len)
|
99
104
|
end
|
100
105
|
|
101
106
|
def get_bytes(offset, len)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiddley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- U.Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Use Fiddle instead of Ruby-FFI !!!
|
14
14
|
email:
|