ffi-additions 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e875a815b30c3d91adfa08e53dcca79b9780d3f8
4
- data.tar.gz: e45441a425e62ad5aab7a785cb1163f5f36b0324
3
+ metadata.gz: 9a068fa44cd053f530bf24ad5f84c720271f1289
4
+ data.tar.gz: 8f8d85c6aa510ef5b1a2118ad76938d9fb7ec5ae
5
5
  SHA512:
6
- metadata.gz: 6f5ef9eb40697ad338799eb30dc4ac0c11c4947c4e5318392c4f53498b465f88aefb91dc19288790b1814b55da9895233d31b390e241558cd71f2e6472a8dfdd
7
- data.tar.gz: f2d75a6cee8908b55d4df98225333c16d5da52d56e14a0cd1d11f66ddb0436cee444b78f9f8fbb22ce29b4e4f54686ee6659029f0776f7297e18517d5f4c63b2
6
+ metadata.gz: b4b8ff9380fd82d299a1451481171579865cf39c4a155af32fa659a9ee66cb35754399e91fa5baa0a16ca8c2efc465b360f15e964f51364eb9f42d401a4a3f1f
7
+ data.tar.gz: f36a2b0acd0fcf5db9b1cc0b3c12559dfb9f44a173c538ef15ba6961dbeaf3cab46b10785d8cbfe4ae71adf35bdd0fbf272015a6ca55c354aefff021f6a788bb
data/README.md CHANGED
@@ -10,11 +10,15 @@ To install:
10
10
  gem install ffi-additions
11
11
  ```
12
12
 
13
- # License
13
+ `FFIAdditions::Struct` - same as FFI::Struct, but with getters and setter defined for all layout fields.
14
+
15
+ `Array::from_pointer_of` - maps pointer to an array of structs
14
16
 
17
+ # License
18
+ ```
15
19
  (The MIT License)
16
20
 
17
- Copyright © 2013 Pedro Miranda
21
+ Copyright © 2016 Pedro Miranda
18
22
 
19
23
  Permission is hereby granted, free of charge, to any person obtaining
20
24
  a copy of this software and associated documentation files (the
@@ -33,4 +37,5 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
37
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
34
38
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
35
39
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
36
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
+ ```
@@ -0,0 +1,11 @@
1
+ module FFIAdditions
2
+ module ArrayUtils
3
+ refine ::Array.singleton_class do
4
+ def from_pointer_of(klass, pointer, size)
5
+ size.times.map do |i|
6
+ klass.new(pointer + i * klass.size)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,10 +3,20 @@ require 'ffi-additions'
3
3
  module FFIAdditions
4
4
  class Struct < FFI::Struct
5
5
  def self.layout(*args)
6
- super
6
+ args = args.first.map do |k, v|
7
+ if v == :string
8
+ v = :pointer
9
+ define_method "#{k}=", ->(s){ self[k] = FFI::MemoryPointer.from_string(s) }
10
+ end
11
+ [k, v]
12
+ end.to_h
13
+ # puts args
14
+ super(args)
7
15
  members.each do |name|
8
16
  unless method_defined?(name)
9
17
  define_method name, ->{ self[name] }
18
+ end
19
+ unless method_defined?("#{name}=")
10
20
  define_method "#{name}=", ->(v){ self[name] = v }
11
21
  end
12
22
  end
@@ -1,3 +1,3 @@
1
1
  module FFIAdditions
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-additions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - P3t3rU5
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-22 00:00:00.000000000 Z
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - README.md
35
35
  - lib/ffi-additions.rb
36
+ - lib/ffi-additions/array.rb
36
37
  - lib/ffi-additions/struct.rb
37
38
  - lib/ffi-additions/version.rb
38
39
  homepage: https://github.com/P3t3rU5/ffi-additions
@@ -55,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
56
  version: '0'
56
57
  requirements: []
57
58
  rubyforge_project:
58
- rubygems_version: 2.6.4
59
+ rubygems_version: 2.6.8
59
60
  signing_key:
60
61
  specification_version: 4
61
62
  summary: Additions to FFI gem