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 +11 -7
- data/lib/opal/typed-array.rb +2 -0
- data/lib/opal/typed-array/array.rb +5 -3
- data/lib/opal/typed-array/buffer.rb +2 -2
- data/lib/opal/typed-array/view.rb +21 -7
- data/opal-typed-array.gemspec +5 -1
- data/spec/array_spec.rb +8 -0
- data/spec/buffer_spec.rb +8 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/spec_runner.html +16 -0
- data/spec/view_spec.rb +7 -0
- metadata +36 -4
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(
|
5
|
+
Opal::DependencyBuilder.new(out: 'build').build
|
7
6
|
end
|
8
7
|
|
9
|
-
desc 'Build latest opal-
|
10
|
-
task :
|
11
|
-
Opal::Builder.new(
|
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
|
-
|
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
|
data/lib/opal/typed-array.rb
CHANGED
@@ -8,11 +8,11 @@
|
|
8
8
|
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
9
|
#++
|
10
10
|
|
11
|
-
|
11
|
+
class Buffer
|
12
12
|
|
13
13
|
class Array
|
14
14
|
def self.for (bits, type)
|
15
|
-
|
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
|
-
|
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`
|
@@ -8,29 +8,43 @@
|
|
8
8
|
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
9
|
#++
|
10
10
|
|
11
|
-
|
11
|
+
class Buffer
|
12
12
|
|
13
13
|
class View
|
14
14
|
include Native
|
15
15
|
|
16
|
-
attr_reader :
|
16
|
+
attr_reader :offset
|
17
17
|
|
18
18
|
def initialize (buffer, offset = nil, length = nil)
|
19
|
-
|
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
|
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
|
47
|
+
`#@native["set" + #{Buffer.name_for bits, type}](offset, value, little)`
|
34
48
|
end
|
35
49
|
|
36
50
|
alias []= set
|
data/opal-typed-array.gemspec
CHANGED
@@ -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
|
}
|
data/spec/array_spec.rb
ADDED
data/spec/buffer_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -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>
|
data/spec/view_spec.rb
ADDED
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
|
-
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
|