Sha256: 7603549f60caf20f3a4548c2fd331f580ce4627bf103a447dceaa592e870a151

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'ffi'
require_relative '../ffi_string'

module Rollenspielsache
  module Dice
    # The Result from a roll
    class RollResult < FFI::AutoPointer
      def self.release(ptr)
        Binding.free ptr
      end

      def to_json(_optional = nil)
        wrap = Binding.to_json self
        wrap.to_s
      end

      def to_s
        Binding.to_string self
      end

      def total
        Binding.total self
      end

      # Rust externs
      module Binding
        include Rollenspielsache
        extend FFI::Library
        ffi_lib 'librollenspielsache'

        # Rust `to_json()`
        attach_function :to_json, :roll_result_to_json, [RollResult], FFIString
        # Rust `to_string()`
        attach_function :to_string, :roll_result_to_string, [RollResult], FFIString
        # It comes back as a base and modifier, total combines them
        attach_function :total, :roll_result_total, [RollResult], :int
        # Pass back to Rust memory management
        attach_function :free, :roll_result_free, [RollResult], :void
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
librollenspielsache-rb-0.1.1 lib/librollenspielsache/dice/roll_result.rb