librollenspielsache-rb 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10c2ae8a313efa474a98ce9e53654ff9168f726e1af15a9ecf70b61b32017fd9
4
- data.tar.gz: 4c01d90db9e0fc3fbd6a896e1f474160f59a57393ad8b176d72a33950a330c3c
3
+ metadata.gz: 9452a60be46275db434a3bd25eed3db89055f86f39bdb432c9103d6cf3176a64
4
+ data.tar.gz: 05e3f1c206856d71030df129bd50172478c05415b03745b59c14f41a17fc06ed
5
5
  SHA512:
6
- metadata.gz: d7fabb447a00c37184b2261b657904cae7b7a027fda17e4b113ceb14f6e9f813fb76d4bb07ec1fac76a55991146755c5a8bfa8cf8cbd8b104795a419bf4a1076
7
- data.tar.gz: 254c94cc749b93c0c64f0adf6899a17144456ef1a7f0913fbb72603f886e734a1466cba111ee103c81602a0075488fb4afa3e33a9c2fb57af4cdb33a972ef85c
6
+ metadata.gz: 0133ac744ff1a8822346cb56f6ed713f1b15ff8e0c9e37f506e6575463c1ca4d65b42cc3ca2e0524040a96cf3ee559131e639343f1d845f58e2dd3ecdd34b6e3
7
+ data.tar.gz: 138ebed85e0713234a2ef2d0deb1607c6166b59b483803eff7e095018208490f4993de10b8296e6c9cbadafe608c2aa00d7517712cb6af3d4bd123cb2b458e41
@@ -1,3 +1,11 @@
1
+ # 0.1.1
2
+
3
+ I was premature in jumping to 0.1. **This is the only working version of 0.1**. Semantic version, take two!
4
+
5
+ * Bump Rust lib
6
+ * Add more tests
7
+ * JSON RollResult
8
+
1
9
  # 0.1.0
2
10
 
3
11
  Mostly just code formats and paths and stuff.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- librollenspielsache-rb (0.1.0)
4
+ librollenspielsache-rb (0.1.1)
5
5
  ffi
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Librollenspielsache-rb
1
+ # Rollenspielsache-rb
2
2
 
3
3
  WIP - there's like nothing actually here yet.
4
4
 
5
- ![Gem](https://img.shields.io/gem/v/librollenspielsache-rb)
5
+ Currently wrapping [librollenspielsache 0.1.2](https://crates.io/crates/librollenspielsache/0.1.2).
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/librollenspielsache-rb.svg)](https://badge.fury.io/rb/librollenspielsache-rb)
6
8
 
7
9
  Ruby bindings for [`librollenspielsache`](https://crates.io/crates/librollenspielsache).
8
10
 
@@ -24,9 +26,22 @@ Or install it yourself as:
24
26
 
25
27
  ## Usage
26
28
 
29
+ Coming soon?
27
30
 
28
31
  ## Development
29
32
 
33
+ ### Prerequisites
34
+
35
+ Before using you need to download and successfully run `make all` in [`librollenspielsache`](https://github.com/deciduously/librollenspielsache). Then, you need to add a file in this project root called `.env` with the following contents:
36
+
37
+ ```
38
+ LD_LIBRARY_PATH="${HOME}/path/to/librollenspielsache/dist"
39
+ ```
40
+
41
+ Adjust to where you build the shared library.
42
+
43
+ ### Run
44
+
30
45
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests or `rake lint` to run RuboCop. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
46
 
32
47
  For now, this expects a pre-compiled `librollenspielsache.so` available in `ext/`. One is provided with the repo.
data/Rakefile CHANGED
@@ -4,13 +4,13 @@ require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'rubocop/rake_task'
6
6
 
7
- ENV['LD_LIBRARY_PATH'] = 'ext'
7
+ ENV['LD_LIBRARY_PATH'] = './ext'
8
8
 
9
9
  RSpec::Core::RakeTask.new(:spec)
10
10
 
11
11
  RuboCop::RakeTask.new(:lint) do |task|
12
12
  task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
13
- task.fail_on_error = false
13
+ task.fail_on_error = false # I'd rather see all of them
14
14
  end
15
15
 
16
16
  task default: :spec
Binary file
@@ -5,6 +5,15 @@ require 'librollenspielsache/dice/roll'
5
5
  require 'librollenspielsache/dice/roll_result'
6
6
  require 'librollenspielsache/version'
7
7
 
8
- module Librollenspielsache
8
+ module Rollenspielsache
9
9
  class Error < StandardError; end
10
+ # Rust exported fns
11
+ module Binding
12
+ include Rollenspielsache::Dice
13
+ extend FFI::Library
14
+ ffi_lib 'librollenspielsache'
15
+
16
+ # Free a string that was passed from the Rust library
17
+ attach_function :free_str, :roll_from_str, [:string], :void
18
+ end
10
19
  end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Librollenspielsache
3
+ require_relative 'roll_result'
4
+ require_relative '../ffi_string'
5
+
6
+ module Rollenspielsache
4
7
  module Dice
5
8
  # A single roll
6
9
  class Roll < FFI::AutoPointer
@@ -26,8 +29,14 @@ module Librollenspielsache
26
29
  Binding.get_repeat self
27
30
  end
28
31
 
32
+ def to_s
33
+ Binding.to_string self
34
+ end
35
+
29
36
  # Rust exported fns
30
37
  module Binding
38
+ include Rollenspielsache
39
+ include Rollenspielsache::Dice
31
40
  extend FFI::Library
32
41
  ffi_lib 'librollenspielsache'
33
42
 
@@ -36,7 +45,9 @@ module Librollenspielsache
36
45
  # Free the object
37
46
  attach_function :free, :roll_free, [], :void
38
47
  # Returns a pointer to RollResult
39
- attach_function :execute, :roll_execute, [Roll], :pointer
48
+ attach_function :execute, :roll_execute, [Roll], Dice::RollResult
49
+ # Get the string
50
+ attach_function :to_string, :roll_from_str, [Roll], FFIString
40
51
  # Get the base
41
52
  attach_function :get_base, :roll_base, [Roll], :int
42
53
  # Get the repeat
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ffi'
4
+ require_relative '../ffi_string'
4
5
 
5
- module Librollenspielsache
6
+ module Rollenspielsache
6
7
  module Dice
7
8
  # The Result from a roll
8
9
  class RollResult < FFI::AutoPointer
@@ -10,17 +11,33 @@ module Librollenspielsache
10
11
  Binding.free ptr
11
12
  end
12
13
 
13
- def to_s(ptr)
14
- Binding.to_s ptr
14
+ def to_json(_optional = nil)
15
+ wrap = Binding.to_json self
16
+ wrap.to_s
17
+ end
18
+
19
+ def to_s
20
+ Binding.to_string self
21
+ end
22
+
23
+ def total
24
+ Binding.total self
15
25
  end
16
26
 
17
27
  # Rust externs
18
28
  module Binding
29
+ include Rollenspielsache
19
30
  extend FFI::Library
20
31
  ffi_lib 'librollenspielsache'
21
32
 
22
- attach_function :to_s, :roll_result_to_string, [:pointer], :string
23
- attach_function :free, :roll_result_free, [:pointer], :void
33
+ # Rust `to_json()`
34
+ attach_function :to_json, :roll_result_to_json, [RollResult], FFIString
35
+ # Rust `to_string()`
36
+ attach_function :to_string, :roll_result_to_string, [RollResult], FFIString
37
+ # It comes back as a base and modifier, total combines them
38
+ attach_function :total, :roll_result_total, [RollResult], :int
39
+ # Pass back to Rust memory management
40
+ attach_function :free, :roll_result_free, [RollResult], :void
24
41
  end
25
42
  end
26
43
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ffi'
4
+
5
+ module Rollenspielsache
6
+ # Wrapped up string
7
+ class FFIString < FFI::AutoPointer
8
+ def self.release
9
+ Binding.free self
10
+ end
11
+
12
+ def to_s
13
+ @to_s ||= read_string.force_encoding('UTF-8')
14
+ end
15
+
16
+ # Rust externs
17
+ module Binding
18
+ extend FFI::Library
19
+ ffi_lib 'librollenspielsache'
20
+
21
+ # Pass back to Rust's memory management
22
+ attach_function :free, :ffi_string_free, [FFIString], :void
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Librollenspielsache
4
- VERSION = '0.1.0'
3
+ module Rollenspielsache
4
+ VERSION = '0.1.1'
5
5
  end
@@ -4,7 +4,7 @@ require_relative 'lib/librollenspielsache/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'librollenspielsache-rb'
7
- spec.version = Librollenspielsache::VERSION
7
+ spec.version = Rollenspielsache::VERSION
8
8
  spec.authors = ['Ben Lovy']
9
9
  spec.email = ['ben@deciduously.com']
10
10
 
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata['source_code_uri'] = 'https://github.com/deciduously/librollenspielsache-rb'
20
20
  spec.metadata['changelog_uri'] = 'https://github.com/deciduously/librollenspielsache-rb/blob/master/CHANGELOG.md'
21
21
 
22
- # spec.add_dependency 'dotenv'
23
22
  spec.add_dependency 'ffi'
24
23
 
25
24
  spec.add_development_dependency 'rubocop'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librollenspielsache-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Lovy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -61,6 +61,7 @@ files:
61
61
  - lib/librollenspielsache.rb
62
62
  - lib/librollenspielsache/dice/roll.rb
63
63
  - lib/librollenspielsache/dice/roll_result.rb
64
+ - lib/librollenspielsache/ffi_string.rb
64
65
  - lib/librollenspielsache/version.rb
65
66
  - librollenspielsache-rb.gemspec
66
67
  homepage: https://rubygems.org/gems/librollenspielsache-rb