opal-typed-array 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +2 -0
- data/Rakefile +14 -0
- data/lib/opal/typed-array.rb +15 -0
- data/lib/opal/typed-array/array.rb +66 -0
- data/lib/opal/typed-array/buffer.rb +42 -0
- data/lib/opal/typed-array/view.rb +63 -0
- data/opal-typed-array.gemspec +14 -0
- metadata +52 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/build
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'opal'
|
3
|
+
|
4
|
+
desc 'Build specified dependencies into .'
|
5
|
+
task :dependencies do
|
6
|
+
Opal::DependencyBuilder.new(stdlib: 'native', out: 'build').build
|
7
|
+
end
|
8
|
+
|
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
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :browser
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
if Opal.undefined?(`ArrayBuffer`)
|
12
|
+
raise NotImplementedError, 'this engine does not support typed arrays'
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'opal/typed-array/buffer'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Buffer
|
12
|
+
|
13
|
+
class Array
|
14
|
+
def self.for (bits, type)
|
15
|
+
`#{Buffer.name_for bits, type}Array`
|
16
|
+
end
|
17
|
+
|
18
|
+
include Native
|
19
|
+
include Enumerable
|
20
|
+
|
21
|
+
attr_reader :buffer, :bits, :type
|
22
|
+
|
23
|
+
def initialize (buffer, bits, type)
|
24
|
+
super(`new #{Array.for(bits, type)}(#{buffer.to_native})`)
|
25
|
+
|
26
|
+
@buffer = buffer
|
27
|
+
@bits = `#@native.BYTES_PER_ELEMENT * 8`
|
28
|
+
@type = type
|
29
|
+
end
|
30
|
+
|
31
|
+
def [] (index, offset=nil)
|
32
|
+
offset ? `#@native.subarray(index, offset)` : `#@native[index]`
|
33
|
+
end
|
34
|
+
|
35
|
+
def []= (index, value)
|
36
|
+
`#@native[index] = value`
|
37
|
+
end
|
38
|
+
|
39
|
+
def bytesize
|
40
|
+
`#@native.byteLength`
|
41
|
+
end
|
42
|
+
|
43
|
+
def each
|
44
|
+
return enum_for :each unless block_given?
|
45
|
+
|
46
|
+
%x{
|
47
|
+
for (var i = 0, length = #@native.length; i < length; i++) {
|
48
|
+
#{yield `#@native[i]`}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def length
|
56
|
+
`#@native.length`
|
57
|
+
end
|
58
|
+
|
59
|
+
def merge! (other, offset = undefined)
|
60
|
+
`#@native.set(#{other.to_native}, offset)`
|
61
|
+
end
|
62
|
+
|
63
|
+
alias size length
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
require 'opal/typed-array/array'
|
12
|
+
require 'opal/typed-array/view'
|
13
|
+
|
14
|
+
class Buffer
|
15
|
+
def self.name_for (bits, type)
|
16
|
+
"#{case type
|
17
|
+
when :unsigned then 'Uint'
|
18
|
+
when :signed then 'Int'
|
19
|
+
when :float then 'Float'
|
20
|
+
end}#{bits}"
|
21
|
+
end
|
22
|
+
|
23
|
+
include Native
|
24
|
+
|
25
|
+
def initialize (size, bits = 1)
|
26
|
+
super(`new ArrayBuffer(size * bits)`)
|
27
|
+
end
|
28
|
+
|
29
|
+
def length
|
30
|
+
`#@native.byteLength`
|
31
|
+
end
|
32
|
+
|
33
|
+
alias size length
|
34
|
+
|
35
|
+
def to_a (bits = 8, type = :unsigned)
|
36
|
+
Array.new(self, bits, type)
|
37
|
+
end
|
38
|
+
|
39
|
+
def view (offset = nil, length = nil)
|
40
|
+
View.new(self, offset, length)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Buffer
|
12
|
+
|
13
|
+
class View
|
14
|
+
include Native
|
15
|
+
|
16
|
+
attr_reader :buffer, :offset, :length
|
17
|
+
|
18
|
+
def initialize (buffer, offset = nil, length = nil)
|
19
|
+
super(`new DataView(#{buffer.to_native}, #{offset.to_native}, #{length.to_native})`)
|
20
|
+
|
21
|
+
@buffer = buffer
|
22
|
+
@offset = offset
|
23
|
+
@length = length
|
24
|
+
end
|
25
|
+
|
26
|
+
def get (offset, bits = 8, type = :unsigned, little = false)
|
27
|
+
`#@native.get#{Buffer.name_for bits, type}(offset, little)`
|
28
|
+
end
|
29
|
+
|
30
|
+
alias [] get
|
31
|
+
|
32
|
+
def set (offset, value, bits = 8, type = :unsigned, little = false)
|
33
|
+
`#@native.set#{Buffer.name_for bits, type}(offset, value, little)`
|
34
|
+
end
|
35
|
+
|
36
|
+
alias []= set
|
37
|
+
|
38
|
+
def get_int8 (offset, little = false); `#@native.getInt8(offset, little)`; end
|
39
|
+
def set_int8 (offset, value, little = false); `#@native.setInt8(offset, value, little)`; end
|
40
|
+
|
41
|
+
def get_uint8 (offset, little = false); `#@native.getUint8(offset, little)`; end
|
42
|
+
def set_uint8 (offset, value, little = false); `#@native.setUint8(offset, value, little)`; end
|
43
|
+
|
44
|
+
def get_int16 (offset, little = false); `#@native.getInt16(offset, little)`; end
|
45
|
+
def set_int16 (offset, value, little = false); `#@native.setInt16(offset, value, little)`; end
|
46
|
+
|
47
|
+
def get_uint16 (offset, little = false); `#@native.getUint16(offset, little)`; end
|
48
|
+
def set_uint16 (offset, value, little = false); `#@native.setUint16(offset, value, little)`; end
|
49
|
+
|
50
|
+
def get_int32 (offset, little = false); `#@native.getInt32(offset, little)`; end
|
51
|
+
def set_int32 (offset, value, little = false); `#@native.setInt32(offset, value, little)`; end
|
52
|
+
|
53
|
+
def get_uint32 (offset, little = false); `#@native.getUint32(offset, little)`; end
|
54
|
+
def set_uint32 (offset, value, little = false); `#@native.setUint32(offset, value, little)`; end
|
55
|
+
|
56
|
+
def get_float32 (offset, little = false); `#@native.getFloat32(offset, little)`; end
|
57
|
+
def set_float32 (offset, value, little = false); `#@native.setFloat32(offset, value, little)`; end
|
58
|
+
|
59
|
+
def get_float64 (offset, little = false); `#@native.getFloat64(offset, little)`; end
|
60
|
+
def set_float64 (offset, value, little = false); `#@native.setFloat64(offset, value, little)`; end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new {|s|
|
2
|
+
s.name = 'opal-typed-array'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.author = 'meh.'
|
5
|
+
s.email = 'meh@paranoici.org'
|
6
|
+
s.homepage = 'http://github.com/opal/opal-typed-array'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.summary = 'Opal support for typed arrays'
|
9
|
+
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
12
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
}
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opal-typed-array
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- meh.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: meh@paranoici.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- lib/opal/typed-array.rb
|
24
|
+
- lib/opal/typed-array/array.rb
|
25
|
+
- lib/opal/typed-array/buffer.rb
|
26
|
+
- lib/opal/typed-array/view.rb
|
27
|
+
- opal-typed-array.gemspec
|
28
|
+
homepage: http://github.com/opal/opal-typed-array
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.10
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Opal support for typed arrays
|
52
|
+
test_files: []
|