opal-typed-array 0.0.1 → 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,14 +1,18 @@
1
- require 'bundler/setup'
2
1
  require 'opal'
3
2
 
4
- desc 'Build specified dependencies into .'
3
+ desc 'Build specified dependencies into build dir'
5
4
  task :dependencies do
6
- Opal::DependencyBuilder.new(stdlib: 'native', out: 'build').build
5
+ Opal::DependencyBuilder.new(out: 'build').build
7
6
  end
8
7
 
9
- desc 'Build latest opal-browser-html5-canvas to current dir'
10
- task :browser do
11
- Opal::Builder.new('lib', join: 'build/opal-typed-array.js').build
8
+ desc 'Build latest opal-typed-array to build dir'
9
+ task :build do
10
+ Opal::Builder.new(files: %w[lib], out: 'build/opal-typed-array.js').build
12
11
  end
13
12
 
14
- task :default => :browser
13
+ desc 'Build latest opal-typed-array ready for testing to build dir'
14
+ task :test => :dependencies do
15
+ Opal::Builder.new(files: %w[lib spec], debug: true, out: 'build/opal-typed-array.test.js').build
16
+ end
17
+
18
+ task :default => :build
@@ -12,4 +12,6 @@ if Opal.undefined?(`ArrayBuffer`)
12
12
  raise NotImplementedError, 'this engine does not support typed arrays'
13
13
  end
14
14
 
15
+ require 'native'
16
+
15
17
  require 'opal/typed-array/buffer'
@@ -8,11 +8,11 @@
8
8
  # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
9
  #++
10
10
 
11
- module Buffer
11
+ class Buffer
12
12
 
13
13
  class Array
14
14
  def self.for (bits, type)
15
- `#{Buffer.name_for bits, type}Array`
15
+ `$opal.global[#{"#{Buffer.name_for bits, type}Array"}]`
16
16
  end
17
17
 
18
18
  include Native
@@ -21,7 +21,9 @@ class Array
21
21
  attr_reader :buffer, :bits, :type
22
22
 
23
23
  def initialize (buffer, bits, type)
24
- super(`new #{Array.for(bits, type)}(#{buffer.to_native})`)
24
+ klass = Array.for(bits, type)
25
+
26
+ super(`new klass(#{buffer.to_native})`)
25
27
 
26
28
  @buffer = buffer
27
29
  @bits = `#@native.BYTES_PER_ELEMENT * 8`
@@ -22,8 +22,8 @@ class Buffer
22
22
 
23
23
  include Native
24
24
 
25
- def initialize (size, bits = 1)
26
- super(`new ArrayBuffer(size * bits)`)
25
+ def initialize (size, bits = 8)
26
+ super(`new ArrayBuffer(size * (bits / 8))`)
27
27
  end
28
28
 
29
29
  def length
@@ -8,29 +8,43 @@
8
8
  # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
9
  #++
10
10
 
11
- module Buffer
11
+ class Buffer
12
12
 
13
13
  class View
14
14
  include Native
15
15
 
16
- attr_reader :buffer, :offset, :length
16
+ attr_reader :offset
17
17
 
18
18
  def initialize (buffer, offset = nil, length = nil)
19
- super(`new DataView(#{buffer.to_native}, #{offset.to_native}, #{length.to_native})`)
19
+ if offset && length
20
+ super(`new DataView(#{buffer.to_native}, #{offset.to_native}, #{length.to_native})`)
21
+ elsif offset
22
+ super(`new DataView(#{buffer.to_native}, #{offset.to_native})`)
23
+ else
24
+ super(`new DataView(#{buffer.to_native})`)
25
+ end
20
26
 
21
- @buffer = buffer
22
27
  @offset = offset
23
- @length = length
24
28
  end
25
29
 
30
+ def buffer
31
+ `#@native.buffer`
32
+ end
33
+
34
+ def length
35
+ `#@native.byteLength`
36
+ end
37
+
38
+ alias size length
39
+
26
40
  def get (offset, bits = 8, type = :unsigned, little = false)
27
- `#@native.get#{Buffer.name_for bits, type}(offset, little)`
41
+ `#@native["get" + #{Buffer.name_for bits, type}](offset, little)`
28
42
  end
29
43
 
30
44
  alias [] get
31
45
 
32
46
  def set (offset, value, bits = 8, type = :unsigned, little = false)
33
- `#@native.set#{Buffer.name_for bits, type}(offset, value, little)`
47
+ `#@native["set" + #{Buffer.name_for bits, type}](offset, value, little)`
34
48
  end
35
49
 
36
50
  alias []= set
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new {|s|
2
2
  s.name = 'opal-typed-array'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.1.1'
4
4
  s.author = 'meh.'
5
5
  s.email = 'meh@paranoici.org'
6
6
  s.homepage = 'http://github.com/opal/opal-typed-array'
@@ -11,4 +11,8 @@ Gem::Specification.new {|s|
11
11
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
12
12
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
13
  s.require_paths = ['lib']
14
+
15
+ s.add_development_dependency 'opal-spec'
16
+
17
+ s.add_dependency 'opal-native'
14
18
  }
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Buffer::Array do
4
+ it 'should get allocated correctly' do
5
+ Buffer.new(8).to_a(32).length.should == 2
6
+ Buffer.new(8).to_a(64, :float).length.should == 1
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Buffer do
4
+ it 'should get allocated correctly' do
5
+ Buffer.new(42).length.should == 42
6
+ Buffer.new(42, 32).length.should == 42 * 4
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ require 'opal/spec/autorun'
2
+ require 'typed-array'
3
+
4
+ if $0 == __FILE__
5
+ Dir['spec/**/*.rb'].each { |spec| require spec }
6
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+
6
+ <title>Spec_runner</title>
7
+
8
+ <script src="../build/opal.debug.js" type="text/javascript" charset="utf-8"></script>
9
+ <script src="../build/opal-spec.debug.js" type="text/javascript" charset="utf-8"></script>
10
+ <script src="../build/opal-native.debug.js" type="text/javascript" charset="utf-8"></script>
11
+ <script src="../build/opal-typed-array.test.debug.js" type="text/javascript" charset="utf-8"></script>
12
+ </head>
13
+
14
+ <body onload="opal.main('/spec/spec_helper.rb')">
15
+ </body>
16
+ </html>
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Buffer::View do
4
+ it 'should get allocated correctly' do
5
+ Buffer.new(8).view.length.should == 8
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-typed-array
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-01-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: opal-spec
16
+ requirement: &21177440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *21177440
25
+ - !ruby/object:Gem::Dependency
26
+ name: opal-native
27
+ requirement: &21177000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *21177000
14
36
  description:
15
37
  email: meh@paranoici.org
16
38
  executables: []
@@ -25,6 +47,11 @@ files:
25
47
  - lib/opal/typed-array/buffer.rb
26
48
  - lib/opal/typed-array/view.rb
27
49
  - opal-typed-array.gemspec
50
+ - spec/array_spec.rb
51
+ - spec/buffer_spec.rb
52
+ - spec/spec_helper.rb
53
+ - spec/spec_runner.html
54
+ - spec/view_spec.rb
28
55
  homepage: http://github.com/opal/opal-typed-array
29
56
  licenses: []
30
57
  post_install_message:
@@ -49,4 +76,9 @@ rubygems_version: 1.8.10
49
76
  signing_key:
50
77
  specification_version: 3
51
78
  summary: Opal support for typed arrays
52
- test_files: []
79
+ test_files:
80
+ - spec/array_spec.rb
81
+ - spec/buffer_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/spec_runner.html
84
+ - spec/view_spec.rb