extras/physfs_rb/physfs/physfs.rb
author Ryan C. Gordon <icculus@icculus.org>
Wed, 11 Dec 2002 15:37:23 +0000
changeset 514 f4e89d934fee
permissions -rw-r--r--
Initial import of Ruby bindings for PhysicsFS.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
514
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
# PhysicsFS - ruby interface
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
#
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
# Author: Ed Sinjiashvili (slimb@vlinkmail.com)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
# License: LGPL
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
#
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
require 'physfs_so'
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
module PhysicsFS
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
  class Version
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
    def initialize major, minor, patch
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
      @major = major
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
      @minor = minor
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
      @patch = patch
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    attr_reader :major, :minor, :patch
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
    def to_s
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
      "#@major.#@minor.#@patch"
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
  end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
  class ArchiveInfo
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
    def initialize ext, desc, author, url
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
      @extension = ext
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
      @description = desc
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
      @author = author
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
      @url = url
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    attr_reader :extension, :description
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    attr_reader :author, :url
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    def to_s
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
      " * #@extension: #@description\n    Written by #@author.\n    #@url\n"
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
  end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
  #
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
  # convenience methods
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
  #
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
  class << self  
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    def init argv0 = $0
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
      init_internal argv0
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    def append_search_path str
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
      add_to_search_path str, 1
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
      self
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    def prepend_search_path str
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
      add_to_search_path str, 0
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
      self
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    alias_method :<<,      :append_search_path
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    alias_method :push,    :append_search_path
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    alias_method :unshift, :prepend_search_path
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    def ls path = ""
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
      enumerate path
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
  end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
  #
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
  # File - PhysicsFS abstract file - can be drawn from various sources
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
  # 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
  class File
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    def write_str str
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
      write str, 1, str.length
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    def cat
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
      prev_pos = tell
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
      seek 0
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
      r = read length, 1
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
      seek prev_pos
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
      r
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
    
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
    alias_method :size, :length
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
  end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
  #
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
  # RWops - general stdio like operations on file-like creatures
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
  #
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
  class RWops
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    SEEK_SET = 0
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
    SEEK_CUR = 1
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    SEEK_END = 2
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    # tell current position of RWopted entity
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    def tell
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
      seek 0, SEEK_CUR
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
    # length of RWops abstracted entity
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
    def length
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
      cur = tell
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
      r = seek 0, SEEK_END
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
      seek cur, SEEK_SET
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
      r
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
    alias_method :size, :length
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
    #
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
    # create rwops from PhysicsFS file object
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    # 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
    def self.from_physfs file
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
      file.to_rwops
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
  end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
end
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
# physfs.rb ends here #