Sha256: 4c09b82fbe7bd9035e0f7410bf52005fd26e0d2bce963f7f8be1dacdc86eac40

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require_relative 'roll_result'
require_relative '../ffi_string'

module Rollenspielsache
  module Dice
    # A single roll
    class Roll < FFI::AutoPointer
      class << self
        def release(ptr)
          Binding.free ptr
        end

        def from_str(str)
          Binding.from_str str
        end
      end

      def execute
        Binding.execute self
      end

      def base
        Binding.get_base self
      end

      def repeat
        Binding.get_repeat self
      end

      def to_s
        Binding.to_string self
      end

      # Rust exported fns
      module Binding
        include Rollenspielsache
        include Rollenspielsache::Dice
        extend FFI::Library
        ffi_lib 'librollenspielsache'

        # Builds a new Roll from a string
        attach_function :from_str, :roll_from_str, [:string], Roll
        # Free the object
        attach_function :free, :roll_free, [], :void
        # Returns a pointer to RollResult
        attach_function :execute, :roll_execute, [Roll], Dice::RollResult
        # Get the string
        attach_function :to_string, :roll_from_str, [Roll], FFIString
        # Get the base
        attach_function :get_base, :roll_base, [Roll], :int
        # Get the repeat
        attach_function :get_repeat, :roll_repeat, [Roll], :uint
      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.rb