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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +17 -2
- data/Rakefile +2 -2
- data/ext/librollenspielsache.so +0 -0
- data/lib/librollenspielsache.rb +10 -1
- data/lib/librollenspielsache/dice/roll.rb +13 -2
- data/lib/librollenspielsache/dice/roll_result.rb +22 -5
- data/lib/librollenspielsache/ffi_string.rb +25 -0
- data/lib/librollenspielsache/version.rb +2 -2
- data/librollenspielsache-rb.gemspec +1 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9452a60be46275db434a3bd25eed3db89055f86f39bdb432c9103d6cf3176a64
|
4
|
+
data.tar.gz: 05e3f1c206856d71030df129bd50172478c05415b03745b59c14f41a17fc06ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0133ac744ff1a8822346cb56f6ed713f1b15ff8e0c9e37f506e6575463c1ca4d65b42cc3ca2e0524040a96cf3ee559131e639343f1d845f58e2dd3ecdd34b6e3
|
7
|
+
data.tar.gz: 138ebed85e0713234a2ef2d0deb1607c6166b59b483803eff7e095018208490f4993de10b8296e6c9cbadafe608c2aa00d7517712cb6af3d4bd123cb2b458e41
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# Rollenspielsache-rb
|
2
2
|
|
3
3
|
WIP - there's like nothing actually here yet.
|
4
4
|
|
5
|
-
|
5
|
+
Currently wrapping [librollenspielsache 0.1.2](https://crates.io/crates/librollenspielsache/0.1.2).
|
6
|
+
|
7
|
+
[](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
|
data/ext/librollenspielsache.so
CHANGED
Binary file
|
data/lib/librollenspielsache.rb
CHANGED
@@ -5,6 +5,15 @@ require 'librollenspielsache/dice/roll'
|
|
5
5
|
require 'librollenspielsache/dice/roll_result'
|
6
6
|
require 'librollenspielsache/version'
|
7
7
|
|
8
|
-
module
|
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
|
-
|
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],
|
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
|
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
|
14
|
-
Binding.
|
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
|
-
|
23
|
-
attach_function :
|
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
|
@@ -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 =
|
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.
|
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-
|
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
|