rufus-lua 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,165 @@
1
+
2
+ #
3
+ # Specifying rufus-lua
4
+ #
5
+ # Fri Mar 13 23:42:29 JST 2009
6
+ #
7
+
8
+ require 'spec_base'
9
+
10
+
11
+ describe Rufus::Lua::State do
12
+
13
+ context 'tables' do
14
+
15
+ before do
16
+ @s = Rufus::Lua::State.new
17
+ end
18
+ after do
19
+ @s.close
20
+ end
21
+
22
+ it 'finds a hash' do
23
+
24
+ @s.eval('h = { a = "b", c = 2, 4 }')
25
+
26
+ expect(@s['h'].to_h).to eq({ 'a' => 'b', 'c' => 2.0, 1.0 => 4.0 })
27
+ end
28
+
29
+ it 'turns a hash into an array' do
30
+
31
+ @s.eval('a = { "a", "b", "c" }')
32
+
33
+ expect(@s['a'].to_h).to eq({ 1.0 => 'a', 2.0 => 'b', 3.0 => 'c' })
34
+ expect(@s['a'].to_a).to eq %w{ a b c }
35
+ end
36
+
37
+ it 'does nested lookups (2)' do
38
+
39
+ @s.eval('a = { b = { c = 0 } }')
40
+
41
+ expect(@s['a.b.c']).to eq 0
42
+ end
43
+
44
+ it 'returns Lua tables' do
45
+
46
+ expect(@s.eval('return {}').class).to eq Rufus::Lua::Table
47
+ end
48
+
49
+ it 'turns Lua tables into Ruby hashes' do
50
+
51
+ expect(@s.eval('return {}').to_h).to eq({})
52
+ end
53
+
54
+ it 'can free Lua tables' do
55
+
56
+ t = @s.eval('t = {}; return t')
57
+ t.free
58
+
59
+ expect(t.ref).to eq nil
60
+ expect(lambda { t.to_h }).to raise_error(RuntimeError)
61
+ end
62
+
63
+ it 'indexes tables' do
64
+
65
+ t = @s.eval("return { a = 'A' }")
66
+
67
+ expect(t['a']).to eq 'A'
68
+ expect(t['b']).to eq nil
69
+ end
70
+
71
+ it 'iterates over Lua tables' do
72
+
73
+ #t = @s.eval("return { a = 'A', b = 'B', c = 3, d = 3.1 }")
74
+ t = @s.eval("return { a = 'A', b = 'B', c = 3 }")
75
+
76
+ expect(t.values.sort_by { |v| v.to_s }).to eq [ 3.0, 'A', 'B' ]
77
+ expect(t.keys.sort).to eq [ 'a', 'b', 'c' ]
78
+ end
79
+
80
+ it 'provides keys and values for tables' do
81
+
82
+ t = @s.eval("return { a = 'A', b = 'B', c = 3 }")
83
+
84
+ expect(t.collect { |k, v| v }.size).to eq 3
85
+ end
86
+
87
+ it 'provides the size of a table' do
88
+
89
+ expect(@s.eval("return { a = 'A', b = 'B', c = 3 }").objlen).to eq 0.0
90
+ expect(@s.eval("return { 1, 2 }").objlen).to eq 2
91
+
92
+ expect(@s.eval("return { a = 'A', b = 'B', c = 3 }").size).to eq 3
93
+ expect(@s.eval("return { a = 'A', b = 'B', c = 3 }").length).to eq 3
94
+ expect(@s.eval("return { 1, 2 }").size).to eq 2
95
+ expect(@s.eval("return { 1, 2 }").length).to eq 2
96
+ end
97
+
98
+ it 'lets setting values in Lua tables from Ruby' do
99
+
100
+ t = @s.eval("return { a = 'A', b = 'B', c = 3 }")
101
+ t['b'] = 4
102
+
103
+ expect(t['b']).to eq 4.0
104
+ end
105
+
106
+ it 'indexes tables properly' do
107
+
108
+ @s.eval("t = { 'a', 'b', 'c' }")
109
+
110
+ expect(@s.eval("return t[0]")).to eq nil
111
+ expect(@s.eval("return t[1]")).to eq 'a'
112
+ expect(@s.eval("return t[3]")).to eq 'c'
113
+ expect(@s.eval("return t[4]")).to eq nil
114
+ end
115
+
116
+ it 'replies to to_a(false) (pure = false)' do
117
+
118
+ expect(@s.eval(
119
+ "return { a = 'A', b = 'B', c = 3 }"
120
+ ).to_a(false).sort).to eq(
121
+ [ [ "a", "A" ], [ "b", "B" ], [ "c", 3.0 ] ]
122
+ )
123
+ expect(@s.eval(
124
+ "return { 1, 2 }"
125
+ ).to_a(false)).to eq(
126
+ [ 1.0, 2.0 ]
127
+ )
128
+ expect(@s.eval(
129
+ "return {}"
130
+ ).to_a(false)).to eq(
131
+ []
132
+ )
133
+ expect(@s.eval(
134
+ "return { 1, 2, car = 'benz' }"
135
+ ).to_a(false)).to eq(
136
+ [ 1.0, 2.0, ["car", "benz"] ]
137
+ )
138
+ end
139
+
140
+ it 'tries hard to honour #to_ruby' do
141
+
142
+ expect(@s.eval(
143
+ "return { a = 'A', b = 'B', c = 3 }"
144
+ ).to_ruby).to eq(
145
+ { "a" => "A", "b" => "B", "c" => 3.0 }
146
+ )
147
+ expect(@s.eval(
148
+ "return { 1, 2 }"
149
+ ).to_ruby).to eq(
150
+ [ 1.0, 2.0 ]
151
+ )
152
+ expect(@s.eval(
153
+ "return {}"
154
+ ).to_ruby).to eq(
155
+ []
156
+ )
157
+ expect(@s.eval(
158
+ "return { 1, 2, car = 'benz' }"
159
+ ).to_ruby).to eq(
160
+ { 1.0 => 1.0, "car" => "benz", 2.0 => 2.0 }
161
+ )
162
+ end
163
+ end
164
+ end
165
+
@@ -0,0 +1,36 @@
1
+
2
+ #
3
+ # Specifying rufus-lua
4
+ #
5
+ # Sat Mar 14 11:39:15 JST 2009
6
+ #
7
+
8
+ require 'spec_base'
9
+
10
+
11
+ describe Rufus::Lua do
12
+
13
+ context '(utils)' do
14
+
15
+ it 'turns Ruby arrays into Lua string representations' do
16
+
17
+ expect(Rufus::Lua.to_lua_s(
18
+ %w{ a b c }
19
+ )).to eq(
20
+ '{ "a", "b", "c" }'
21
+ )
22
+
23
+ # TODO : ["a"] is probably better...
24
+ end
25
+
26
+ it 'turns Ruby hashes into Lua string representations' do
27
+
28
+ expect(Rufus::Lua.to_lua_s(
29
+ { 'a' => 'A', 'b' => 2}
30
+ )).to eq(
31
+ '{ ["a"] = "A", ["b"] = 2 }'
32
+ )
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,41 @@
1
+
2
+ #
3
+ # benchmarking rufus-lua
4
+ #
5
+ # Thu Mar 12 15:40:26 JST 2009
6
+ #
7
+
8
+ $:.unshift('lib')
9
+
10
+ require 'benchmark'
11
+
12
+ require 'rubygems'
13
+ require 'rufus/lua'
14
+
15
+
16
+ Benchmark.benchmark(' ' * 31 + Benchmark::Tms::CAPTION, 31) do |b|
17
+
18
+ b.report('ruby') do
19
+ 1_000_000.times { |i| i }
20
+ end
21
+
22
+ s = Rufus::Lua::State.new
23
+ b.report('lua') do
24
+ s.eval('for i = 1, 1000000 do end')
25
+ end
26
+ s.close
27
+ end
28
+
29
+ # jmettraux@sanma ~/rufus/rufus-lua (master) $ ruby test/bm0.rb
30
+ # user system total real
31
+ # ruby 0.220000 0.000000 0.220000 ( 0.217909)
32
+ # lua 0.010000 0.000000 0.010000 ( 0.013667)
33
+ # jmettraux@sanma ~/rufus/rufus-lua (master) $ ruby19 test/bm0.rb
34
+ # user system total real
35
+ # ruby 0.120000 0.010000 0.130000 ( 0.123396)
36
+ # lua 0.010000 0.000000 0.010000 ( 0.013869)
37
+ # jmettraux@sanma ~/rufus/rufus-lua (master) $ ruby19 test/bm0.rb
38
+ # user system total real
39
+ # ruby 0.110000 0.000000 0.110000 ( 0.125229)
40
+ # lua 0.020000 0.000000 0.020000 ( 0.012828)
41
+
@@ -0,0 +1,78 @@
1
+
2
+ #
3
+ # benchmarking rufus-lua
4
+ #
5
+ # Thu Mar 12 15:40:26 JST 2009
6
+ #
7
+
8
+ $:.unshift('lib')
9
+
10
+ require 'benchmark'
11
+
12
+ require 'rubygems'
13
+ require 'rufus/lua'
14
+
15
+ RUBYFIBS = Fiber.new do
16
+ n1 = n2 = 1
17
+ loop do
18
+ Fiber.yield n1
19
+ n1, n2 = n2, n1+n2
20
+ end
21
+ end
22
+ #20.times { print RUBYFIBS.resume, ' ' }
23
+
24
+ s = %{
25
+ co = coroutine.create(function ()
26
+ local n1 = 1; local n2 = 1
27
+ while true do
28
+ coroutine.yield(n1)
29
+ n1, n2 = n2, n1+n2
30
+ end
31
+ end)
32
+ return co
33
+ }
34
+
35
+ LUA = Rufus::Lua::State.new
36
+ LUAFIBS = LUA.eval(s)
37
+ #20.times { print LUAFIBS.resume, ' ' }
38
+
39
+ N = 10_000
40
+ Benchmark.benchmark(' ' * 31 + Benchmark::Tms::CAPTION, 31) do |b|
41
+ b.report('ruby') do
42
+ N.times { RUBYFIBS.resume }
43
+ end
44
+ b.report('lua via ruby') do
45
+ N.times { LUAFIBS.resume }
46
+ end
47
+ b.report('lua') do
48
+ LUA.eval("for i = 0, #{N} do coroutine.resume(co) end")
49
+ end
50
+ end
51
+
52
+ LUA.close
53
+
54
+
55
+ # $ ruby19 test/bm_fiber.rb
56
+ # user system total real
57
+ # ruby 0.050000 0.010000 0.060000 ( 0.054605)
58
+ # lua via ruby 0.180000 0.000000 0.180000 ( 0.189010)
59
+ # lua 0.010000 0.000000 0.010000 ( 0.005543)
60
+ #
61
+ # $ ruby19 test/bm_fiber.rb
62
+ # user system total real
63
+ # ruby 0.050000 0.000000 0.050000 ( 0.051531)
64
+ # lua via ruby 0.180000 0.010000 0.190000 ( 0.194944)
65
+ # lua 0.010000 0.000000 0.010000 ( 0.006325)
66
+ #
67
+ # $ ruby19 test/bm_fiber.rb
68
+ # user system total real
69
+ # ruby 0.050000 0.010000 0.060000 ( 0.052032)
70
+ # lua via ruby 0.180000 0.000000 0.180000 ( 0.195411)
71
+ # lua 0.010000 0.000000 0.010000 ( 0.006394)
72
+ #
73
+ # $ ruby19 test/bm_fiber.rb
74
+ # user system total real
75
+ # ruby 0.050000 0.010000 0.060000 ( 0.054892)
76
+ # lua via ruby 0.180000 0.000000 0.180000 ( 0.267880)
77
+ # lua 0.000000 0.000000 0.000000 ( 0.005865)
78
+
@@ -0,0 +1,43 @@
1
+
2
+ #
3
+ # benchmarking rufus-lua
4
+ #
5
+ # Tue Mar 17 15:02:27 JST 2009
6
+ #
7
+
8
+ $:.unshift('lib')
9
+
10
+ require 'benchmark'
11
+
12
+ require 'rubygems'
13
+ require 'rufus/lua'
14
+
15
+ code = %{
16
+ for i = 1, 10000 do
17
+ local a = {}
18
+ for j = 1, 2000 do
19
+ a[#a] = j
20
+ end
21
+ end
22
+ }
23
+
24
+ Benchmark.benchmark(' ' * 31 + Benchmark::Tms::CAPTION, 31) do |b|
25
+
26
+ l = Rufus::Lua::State.new
27
+
28
+ b.report('lua (GC on)') do
29
+ l.eval(code)
30
+ end
31
+
32
+ l.close
33
+
34
+ l = Rufus::Lua::State.new
35
+ l.gc_stop
36
+
37
+ b.report('lua (GC off)') do
38
+ l.eval(code)
39
+ end
40
+
41
+ l.close
42
+ end
43
+
@@ -0,0 +1,19 @@
1
+ #
2
+ # Test garbage collection API from rufus-lua
3
+ #
4
+
5
+ $:.unshift('lib')
6
+
7
+ require 'rubygems'
8
+ require 'rufus/lua'
9
+
10
+
11
+ puts "Creating a new state..."
12
+ s = Rufus::Lua::State.new
13
+ puts " #{s.gc_count} KB in use by Lua interpreter"
14
+ puts " Calling into Lua..."
15
+ puts s.eval("return table.concat({ ' hello', 'from', 'Lua' }, ' ')")
16
+ puts " #{s.gc_count} KB in use by Lua interpreter"
17
+ puts "Performing forced garbage collection..."
18
+ s.gc_collect!
19
+ puts " #{s.gc_count} KB in use by Lua interpreter"
@@ -0,0 +1,19 @@
1
+
2
+ #
3
+ # sandbox experiment file with rufus-lua
4
+ #
5
+ # Thu Mar 12 15:54:30 JST 2009
6
+ #
7
+
8
+ $:.unshift('lib')
9
+
10
+ require 'rubygems'
11
+ require 'rufus/lua'
12
+
13
+
14
+ s = Rufus::Lua::State.new
15
+
16
+ puts s.eval("return table.concat({ 'hello', 'from', 'Lua' }, ' ')")
17
+
18
+ s.close
19
+
metadata CHANGED
@@ -1,79 +1,128 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rufus-lua
3
- version: !ruby/object:Gem::Version
4
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - John Mettraux
8
9
  - Alain Hoang
9
10
  - Scott Persinger
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
-
14
- date: 2009-09-30 00:00:00 +09:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
14
+ date: 2014-06-30 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
18
17
  name: ffi
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '1.9'
19
24
  type: :runtime
20
- version_requirement:
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: "0"
26
- version:
27
- description:
28
- email: jmettraux@gmail.com
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '1.9'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rake
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.13.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 2.13.0
64
+ description: ruby-ffi based bridge from Ruby to Lua
65
+ email:
66
+ - jmettraux@gmail.com
29
67
  executables: []
30
-
31
68
  extensions: []
32
-
33
- extra_rdoc_files:
34
- - README.rdoc
35
- - CHANGELOG.txt
36
- - CREDITS.txt
37
- - LICENSE.txt
38
- files:
39
- - lib/rufus/lua/lib.rb
40
- - lib/rufus/lua/objects.rb
69
+ extra_rdoc_files: []
70
+ files:
71
+ - Rakefile
72
+ - lib/rufus-lua.rb
73
+ - lib/rufus/lua.rb
74
+ - lib/rufus/lua/error.rb
41
75
  - lib/rufus/lua/state.rb
76
+ - lib/rufus/lua/lib.rb
77
+ - lib/rufus/lua/version.rb
42
78
  - lib/rufus/lua/utils.rb
43
- - lib/rufus/lua.rb
44
- - lib/rufus-lua.rb
79
+ - lib/rufus/lua/objects.rb
80
+ - spec/tables_spec.rb
81
+ - spec/functions_spec.rb
82
+ - spec/utils_spec.rb
83
+ - spec/rfunctions_spec.rb
84
+ - spec/coroutines_spec.rb
85
+ - spec/eval_spec.rb
86
+ - spec/state_spec.rb
87
+ - spec/spec_base.rb
88
+ - spec/string_spec.rb
89
+ - spec/gc_spec.rb
90
+ - spec/lib_spec.rb
91
+ - spec/spec.rb
92
+ - test/bm0.rb
93
+ - test/t.rb
94
+ - test/gc0.rb
95
+ - test/bm_gc_stop.rb
96
+ - test/bm_fiber.rb
97
+ - rufus-lua.gemspec
45
98
  - CHANGELOG.txt
46
- - CREDITS.txt
47
- - LICENSE.txt
48
99
  - TODO.txt
49
- - README.rdoc
50
- has_rdoc: true
51
- homepage: http://rufus.rubyforge.org/
52
- licenses: []
53
-
100
+ - LICENSE.txt
101
+ - CREDITS.txt
102
+ - README.md
103
+ homepage: https://github.com/jmettraux/rufus-lua
104
+ licenses:
105
+ - MIT
54
106
  post_install_message:
55
107
  rdoc_options: []
56
-
57
- require_paths:
108
+ require_paths:
58
109
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
65
- required_rubygems_version: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- version:
71
- requirements:
72
- - ffi
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
73
123
  rubyforge_project: rufus
74
- rubygems_version: 1.3.5
124
+ rubygems_version: 1.8.23
75
125
  signing_key:
76
126
  specification_version: 3
77
127
  summary: ruby-ffi based bridge from Ruby to Lua
78
- test_files:
79
- - spec/spec.rb
128
+ test_files: []