Tamar 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +21 -3
- data/Rakefile +3 -0
- data/Tamar.gemspec +27 -2
- data/VERSION +1 -1
- data/src/build/extconf.rb +2 -0
- data/src/rubyluabridge/.hg_archival.txt +2 -0
- data/src/rubyluabridge/.project +91 -0
- data/src/rubyluabridge/LICENSE +31 -0
- data/src/rubyluabridge/LUA_IN_RUBY +146 -0
- data/src/rubyluabridge/README +129 -0
- data/src/rubyluabridge/RUBY_IN_LUA +25 -0
- data/src/rubyluabridge/Rakefile +88 -0
- data/src/rubyluabridge/build/extconf_osx.sh +2 -0
- data/src/rubyluabridge/build/extconf_ubuntu.sh +2 -0
- data/src/rubyluabridge/debian/changelog +34 -0
- data/src/rubyluabridge/debian/compat +1 -0
- data/src/rubyluabridge/debian/control +29 -0
- data/src/rubyluabridge/debian/copyright +34 -0
- data/src/rubyluabridge/debian/libluabridge-ruby1.8.doc-base +11 -0
- data/src/rubyluabridge/debian/libluabridge-ruby1.8.docs +2 -0
- data/src/rubyluabridge/debian/libluabridge-ruby1.8.install +1 -0
- data/src/rubyluabridge/debian/rules +65 -0
- data/src/rubyluabridge/debian/watch +2 -0
- data/src/rubyluabridge/doc/jamis.rb +591 -0
- data/src/rubyluabridge/extconf.rb +48 -0
- data/src/rubyluabridge/rubyluabridge.cc +1623 -0
- data/src/rubyluabridge/rubyluabridge.h +81 -0
- data/src/rubyluabridge/tests/lua_in_ruby_test.rb +508 -0
- metadata +28 -4
@@ -0,0 +1,81 @@
|
|
1
|
+
/*
|
2
|
+
* RubyLuaBridge
|
3
|
+
*
|
4
|
+
* Licensed under the BSD License:
|
5
|
+
*
|
6
|
+
* Copyright (c) 2007, Evan Wies
|
7
|
+
* All rights reserved.
|
8
|
+
*
|
9
|
+
* Redistribution and use in source and binary forms, with or without
|
10
|
+
* modification, are permitted provided that the following conditions are met:
|
11
|
+
* * Redistributions of source code must retain the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer.
|
13
|
+
* * Redistributions in binary form must reproduce the above copyright
|
14
|
+
* notice, this list of conditions and the following disclaimer in the
|
15
|
+
* documentation and/or other materials provided with the distribution.
|
16
|
+
* * Neither the name of 'neomantra' nor the
|
17
|
+
* names of its contributors may be used to endorse or promote products
|
18
|
+
* derived from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY Evan Wies ``AS IS'' AND ANY
|
21
|
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL Evan Wies BE LIABLE FOR ANY
|
24
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
27
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
*/
|
31
|
+
|
32
|
+
#ifndef NEOMANTRA_RUBYLUABRIDGE_H_
|
33
|
+
#define NEOMANTRA_RUBYLUABRIDGE_H_
|
34
|
+
|
35
|
+
#include <lua.h>
|
36
|
+
#include <ruby.h>
|
37
|
+
|
38
|
+
#include <boost/shared_ptr.hpp>
|
39
|
+
|
40
|
+
// Version Information
|
41
|
+
#define RUBYLUABRIDGE_VERSION ("0.7")
|
42
|
+
#define RUBYLUABRIDGE_VERSION_NUM (000700)
|
43
|
+
|
44
|
+
|
45
|
+
// shared_ptr deleter which invokes lua_close
|
46
|
+
struct lua_close_deleter
|
47
|
+
{
|
48
|
+
void operator()(lua_State* L)
|
49
|
+
{
|
50
|
+
lua_close(L);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
/// Struct for our Ruby Lua::State.
|
55
|
+
/// Manages the lifetime of a lua_State using a shared_ptr
|
56
|
+
struct rlua_State
|
57
|
+
{
|
58
|
+
lua_State* getState() { return Lstate.get(); }
|
59
|
+
|
60
|
+
boost::shared_ptr<lua_State> Lstate; /// The lua_State we are wrapping
|
61
|
+
};
|
62
|
+
|
63
|
+
|
64
|
+
/// Struct for our Ruby Lua::Object.
|
65
|
+
///
|
66
|
+
/// We use it to persist Lua object beyond its lifetime on the Lua stack.
|
67
|
+
///
|
68
|
+
/// It uses Lua's "standard" reference system:
|
69
|
+
/// http://www.lua.org/manual/5.1/manual.html#luaL_ref
|
70
|
+
/// We follow the convention of using Lua's registry to store the references.
|
71
|
+
struct rlua_RefObject
|
72
|
+
{
|
73
|
+
lua_State* getState() { return Lstate.get(); }
|
74
|
+
|
75
|
+
boost::shared_ptr<lua_State> Lstate; /// The lua_State where the reference is held.
|
76
|
+
int Lref; /// The reference id
|
77
|
+
VALUE Rstate; /// The Ruby Lua::State where this ref came from
|
78
|
+
};
|
79
|
+
|
80
|
+
|
81
|
+
#endif // NEOMANTRA_RUBYLUABRIDGE_H_
|
@@ -0,0 +1,508 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require 'rubyluabridge'
|
4
|
+
require 'stringio'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
|
8
|
+
class LuaInRuby_Test < Test::Unit::TestCase
|
9
|
+
|
10
|
+
# test module-level entities
|
11
|
+
def test_module
|
12
|
+
assert_not_nil( Lua::BRIDGE_VERSION )
|
13
|
+
assert_not_nil( Lua::BRIDGE_VERSION_NUM )
|
14
|
+
assert_not_nil( Lua::LUA_VERSION )
|
15
|
+
assert_not_nil( Lua::LUA_RELEASE )
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# test construction of various entities
|
20
|
+
def test_construction
|
21
|
+
l = Lua::State.new
|
22
|
+
|
23
|
+
assert_instance_of Lua::State, l
|
24
|
+
assert_instance_of Lua::Table, l.__globals
|
25
|
+
assert_instance_of Lua::Table, l.__registry
|
26
|
+
|
27
|
+
assert_equal l, l.__state
|
28
|
+
assert_equal l, l.__globals.__state
|
29
|
+
assert_equal l, l.__registry.__state
|
30
|
+
|
31
|
+
assert_luastack_clean l
|
32
|
+
|
33
|
+
assert_raise TypeError do
|
34
|
+
l_bad = Lua::State.new "aa"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# test the basic types
|
40
|
+
def test_basic_types
|
41
|
+
l = Lua::State.new
|
42
|
+
|
43
|
+
# eval, and basic marshaling
|
44
|
+
assert_nil l.eval('return')
|
45
|
+
assert_nil l.eval('return nil')
|
46
|
+
assert_equal 1, l.eval('return 1')
|
47
|
+
assert_equal 1.1, l.eval('return 1.1')
|
48
|
+
assert_equal 'abc', l.eval('return "abc"')
|
49
|
+
assert_equal true, l.eval('return true')
|
50
|
+
assert_equal false, l.eval('return false')
|
51
|
+
|
52
|
+
# multi-ret
|
53
|
+
a = l.eval_mult( "return" )
|
54
|
+
assert_instance_of Array, a
|
55
|
+
assert_equal [], a
|
56
|
+
assert_equal 0, a.length
|
57
|
+
a = l.eval_mult( "return 1" )
|
58
|
+
assert_instance_of Array, a
|
59
|
+
assert_equal [1], a
|
60
|
+
assert_equal 1, a.length
|
61
|
+
a = l.eval_mult( "return 1, 2, 3, 4" )
|
62
|
+
assert_instance_of Array, a
|
63
|
+
assert_equal [1,2,3,4], a
|
64
|
+
assert_equal 4, a.length
|
65
|
+
|
66
|
+
# type id
|
67
|
+
l.eval <<LUA_END
|
68
|
+
f = function() end
|
69
|
+
t = {}
|
70
|
+
u = io.output() -- userdata
|
71
|
+
LUA_END
|
72
|
+
assert_equal Lua::TFUNCTION, l['f'].__type
|
73
|
+
assert_equal Lua::TTABLE, l.t.__type
|
74
|
+
assert_equal Lua::TUSERDATA, l.u.__type
|
75
|
+
|
76
|
+
# access queries
|
77
|
+
assert_equal true, l.indexable?
|
78
|
+
assert_equal true, l.new_indexable?
|
79
|
+
assert_equal false, l.callable?
|
80
|
+
assert_equal true, l.t.indexable?
|
81
|
+
assert_equal true, l.t.new_indexable?
|
82
|
+
assert_equal false, l.t.callable?
|
83
|
+
assert_equal false, l['f'].indexable?
|
84
|
+
assert_equal false, l['f'].new_indexable?
|
85
|
+
assert_equal true, l['f'].callable?
|
86
|
+
assert_equal true, l['u'].indexable?
|
87
|
+
assert_equal false, l['u'].new_indexable?
|
88
|
+
assert_equal false, l['u'].callable?
|
89
|
+
|
90
|
+
assert_luastack_clean l
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# test setters
|
95
|
+
def test_setters
|
96
|
+
l = Lua::State.new
|
97
|
+
|
98
|
+
l.v = 5 ; assert_equal 5, l.v
|
99
|
+
l.a = {} ; assert_instance_of Lua::Table, l.a
|
100
|
+
l.a.v = 7 ; assert_equal 7, l.a.v
|
101
|
+
|
102
|
+
l['b'] = 6 ; assert_equal 6, l.b
|
103
|
+
l.a['b'] = 7 ; assert_equal 7, l.a.b
|
104
|
+
|
105
|
+
assert_luastack_clean l
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
# test libraries
|
110
|
+
def test_libraries
|
111
|
+
# invoking libraries
|
112
|
+
l = Lua::State.new
|
113
|
+
assert_nothing_thrown do
|
114
|
+
STDOUT << "you should see-> Hello from Lua!-> "
|
115
|
+
l.eval( 'print "Hello from Lua!"' )
|
116
|
+
STDOUT << "you should see-> Hello again from Lua!-> "
|
117
|
+
l.print "Hello again from Lua!"
|
118
|
+
end
|
119
|
+
assert_luastack_clean l
|
120
|
+
|
121
|
+
# loading libraries
|
122
|
+
#####################
|
123
|
+
|
124
|
+
l = Lua::State.new # all
|
125
|
+
count = 0 ; l.__globals.each_key { |k| count += 1 }
|
126
|
+
assert_equal 39, count
|
127
|
+
assert_instance_of Lua::RefObject, l['ipairs'] # base library check
|
128
|
+
assert_instance_of Lua::Table, l.package
|
129
|
+
assert_instance_of Lua::Table, l.table
|
130
|
+
assert_instance_of Lua::Table, l.io
|
131
|
+
assert_instance_of Lua::Table, l.os
|
132
|
+
assert_instance_of Lua::Table, l.string
|
133
|
+
assert_instance_of Lua::Table, l.math
|
134
|
+
assert_instance_of Lua::Table, l.debug
|
135
|
+
|
136
|
+
l = Lua::State.new( :loadlibs => :all )
|
137
|
+
count = 0 ; l.__globals.each_key { |k| count += 1 }
|
138
|
+
assert_equal 39, count
|
139
|
+
assert_instance_of Lua::RefObject, l['ipairs'] # base library check
|
140
|
+
assert_instance_of Lua::Table, l.package
|
141
|
+
assert_instance_of Lua::Table, l.table
|
142
|
+
assert_instance_of Lua::Table, l.io
|
143
|
+
assert_instance_of Lua::Table, l.os
|
144
|
+
assert_instance_of Lua::Table, l.string
|
145
|
+
assert_instance_of Lua::Table, l.math
|
146
|
+
assert_instance_of Lua::Table, l.debug
|
147
|
+
|
148
|
+
l = Lua::State.new( :loadlibs => :none )
|
149
|
+
count = 0 ; l.__globals.each_key { |k| count += 1 }
|
150
|
+
assert_equal 0, count
|
151
|
+
|
152
|
+
l = Lua::State.new( :loadlibs => :base )
|
153
|
+
assert_instance_of Lua::RefObject, l['ipairs'] # base library check
|
154
|
+
assert_equal nil, l.string
|
155
|
+
l = Lua::State.new( :loadlibs => :package )
|
156
|
+
assert_instance_of Lua::Table, l.package
|
157
|
+
assert_equal nil, l.string
|
158
|
+
l = Lua::State.new( :loadlibs => :table )
|
159
|
+
assert_instance_of Lua::Table, l.table
|
160
|
+
assert_equal nil, l.string
|
161
|
+
l = Lua::State.new( :loadlibs => :io )
|
162
|
+
assert_instance_of Lua::Table, l.io
|
163
|
+
assert_equal nil, l.string
|
164
|
+
l = Lua::State.new( :loadlibs => :os )
|
165
|
+
assert_instance_of Lua::Table, l.os
|
166
|
+
assert_equal nil, l.string
|
167
|
+
l = Lua::State.new( :loadlibs => :string )
|
168
|
+
assert_instance_of Lua::Table, l.string
|
169
|
+
assert_equal nil, l.io
|
170
|
+
l = Lua::State.new( :loadlibs => :math )
|
171
|
+
assert_instance_of Lua::Table, l.math
|
172
|
+
assert_equal nil, l.string
|
173
|
+
l = Lua::State.new( :loadlibs => :debug )
|
174
|
+
assert_instance_of Lua::Table, l.debug
|
175
|
+
assert_equal nil, l.string
|
176
|
+
|
177
|
+
l = Lua::State.new( :loadlibs => [:base, :package, :io] )
|
178
|
+
assert_instance_of Lua::RefObject, l['ipairs'] # base library check
|
179
|
+
assert_instance_of Lua::Table, l.package
|
180
|
+
assert_instance_of Lua::Table, l.io
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
# test table creation from ruby
|
185
|
+
def test_table_creation_from_ruby
|
186
|
+
l = Lua::State.new
|
187
|
+
|
188
|
+
l.eval( "a = {}")
|
189
|
+
assert_instance_of Lua::Table, l.a
|
190
|
+
|
191
|
+
s = "return {1,2,3}"
|
192
|
+
assert_instance_of Lua::Table, l.eval(s)
|
193
|
+
assert_equal 3, l.eval(s).__length
|
194
|
+
assert_equal [1,2,3], l.eval(s).to_array
|
195
|
+
|
196
|
+
b = l.new_table_at 'b'
|
197
|
+
assert_instance_of Lua::Table, b
|
198
|
+
assert_instance_of Lua::Table, l.b
|
199
|
+
|
200
|
+
b = l.a.new_table_at 'b'
|
201
|
+
assert_instance_of Lua::Table, b
|
202
|
+
assert_instance_of Lua::Table, l.a.b
|
203
|
+
|
204
|
+
l.c = []
|
205
|
+
assert_instance_of Lua::Table, l.c
|
206
|
+
assert_equal 0, l.c.__length
|
207
|
+
|
208
|
+
l.d = {}
|
209
|
+
assert_instance_of Lua::Table, l.d
|
210
|
+
assert_equal 0, l.d.__length
|
211
|
+
|
212
|
+
e = [1,2,3,4]
|
213
|
+
l.e = e
|
214
|
+
assert_equal 1, l.e[1]
|
215
|
+
assert_equal 2, l.e[2]
|
216
|
+
assert_equal 3, l.e[3]
|
217
|
+
assert_equal 4, l.e[4]
|
218
|
+
assert_equal e, l.e.to_array
|
219
|
+
assert_instance_of Lua::Table, l.e
|
220
|
+
|
221
|
+
f = { 1=>1, 2=>2, 'a'=>3, 'b'=>4 }
|
222
|
+
l.f = f
|
223
|
+
assert_equal 1, l.f[1]
|
224
|
+
assert_equal 2, l.f[2]
|
225
|
+
assert_equal 3, l.f['a']
|
226
|
+
assert_equal 4, l.f['b']
|
227
|
+
assert_equal 2, l.f.__length
|
228
|
+
assert_instance_of Lua::Table, l.f
|
229
|
+
|
230
|
+
assert_luastack_clean l
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
# test table accesses
|
235
|
+
def test_table_access
|
236
|
+
l = Lua::State.new
|
237
|
+
l.eval <<LUA_END
|
238
|
+
a = { 1, 2, 3, 4 }
|
239
|
+
h = { a='x', b='y',
|
240
|
+
[true] = 'a',
|
241
|
+
[false] = 'b',
|
242
|
+
[1.3] = 'z', }
|
243
|
+
h2 = { a='x', b='y', }
|
244
|
+
LUA_END
|
245
|
+
|
246
|
+
assert_instance_of Lua::Table, l.a
|
247
|
+
assert_instance_of Lua::Table, l.h
|
248
|
+
assert_instance_of Lua::Table, l.h2
|
249
|
+
assert_instance_of Lua::Table, l['a']
|
250
|
+
assert_instance_of Lua::Table, l['h']
|
251
|
+
assert_instance_of Lua::Table, l['h2']
|
252
|
+
|
253
|
+
assert_nil l.a[0]
|
254
|
+
assert_equal 1, l.a[1]
|
255
|
+
assert_equal 2, l.a[2]
|
256
|
+
assert_equal 3, l.a[3]
|
257
|
+
assert_equal 4, l.a[4]
|
258
|
+
assert_equal 4, l.a.__length
|
259
|
+
|
260
|
+
assert_equal 'x', l.h.a
|
261
|
+
assert_equal 'y', l.h.b
|
262
|
+
|
263
|
+
assert_nil l.h[0]
|
264
|
+
assert_equal 'x', l.h['a']
|
265
|
+
assert_equal 'y', l.h['b']
|
266
|
+
|
267
|
+
assert_equal 'z', l.h[1.3]
|
268
|
+
assert_equal 'a', l.h[true]
|
269
|
+
assert_equal 'b', l.h[false]
|
270
|
+
assert_equal 0, l.h.__length # length only applies to Array
|
271
|
+
|
272
|
+
temp = (l.a[10] = 'x')
|
273
|
+
assert_equal 'x', temp
|
274
|
+
assert_equal 'x', l.a[10]
|
275
|
+
|
276
|
+
assert_instance_of Array, l.a.to_array
|
277
|
+
assert_instance_of Hash, l.h2.to_hash
|
278
|
+
assert_equal( [1,2,3,4], l.a.to_array)
|
279
|
+
assert_equal( {'a' => 'x','b' => 'y'}, l.h2.to_hash)
|
280
|
+
|
281
|
+
assert_luastack_clean l
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
# test table iteration
|
286
|
+
def test_table_iteration
|
287
|
+
l = Lua::State.new
|
288
|
+
|
289
|
+
# array integer iteration
|
290
|
+
l.eval( "array = { 100, 200, 300, 400 }" )
|
291
|
+
assert_instance_of Lua::Table, l.array
|
292
|
+
n = 0 ; l.array.each_ipair { |k,v| n += 1
|
293
|
+
assert_pairs_match( k, v, 1, 100 )
|
294
|
+
assert_pairs_match( k, v, 2, 200 )
|
295
|
+
assert_pairs_match( k, v, 3, 300 )
|
296
|
+
assert_pairs_match( k, v, 4, 400 )
|
297
|
+
}
|
298
|
+
assert_equal(4, n)
|
299
|
+
|
300
|
+
n = 0 ; l.array.each_ikey { |k| n += 1
|
301
|
+
assert_pairs_match( n, k, 1, 1 )
|
302
|
+
assert_pairs_match( n, k, 2, 2 )
|
303
|
+
assert_pairs_match( n, k, 3, 3 )
|
304
|
+
assert_pairs_match( n, k, 4, 4 )
|
305
|
+
assert( n <= 4 )
|
306
|
+
}
|
307
|
+
assert_equal(4, n)
|
308
|
+
|
309
|
+
sumv = n = 0 ; l.array.each_ivalue { |v| n += 1
|
310
|
+
sumv += v
|
311
|
+
assert_equal(v, n*100)
|
312
|
+
}
|
313
|
+
assert_equal(4, n) ; assert_equal(1000, sumv)
|
314
|
+
|
315
|
+
# hash integer iteration
|
316
|
+
l.eval( "hsh = { [1]=100, [2]=200, a=300, b=400, }" )
|
317
|
+
assert_instance_of Lua::Table, l.hsh
|
318
|
+
n = 0 ; l.hsh.each_ipair { |k,v| n += 1
|
319
|
+
assert_pairs_match( k, v, 1, 100 )
|
320
|
+
assert_pairs_match( k, v, 2, 200 )
|
321
|
+
assert_pairs_match( k, v, 'a', 300 )
|
322
|
+
assert_pairs_match( k, v, 'b', 400 )
|
323
|
+
}
|
324
|
+
assert_equal(2, n)
|
325
|
+
|
326
|
+
sumk = n = 0 ; l.hsh.each_ikey { |k| n += 1
|
327
|
+
sumk += k
|
328
|
+
}
|
329
|
+
assert_equal(2, n) ; assert_equal(3, sumk)
|
330
|
+
|
331
|
+
sumv = n = 0 ; l.hsh.each_ivalue { |v| n += 1
|
332
|
+
sumv += v
|
333
|
+
assert_equal(v, n*100)
|
334
|
+
}
|
335
|
+
assert_equal(2, n) ; assert_equal(300, sumv)
|
336
|
+
|
337
|
+
# array assoc iteration
|
338
|
+
l.eval( "array = { 100, 200, 300, 400 }" )
|
339
|
+
assert_instance_of Lua::Table, l.array
|
340
|
+
n = 0 ; l.array.each_pair { |k,v| n += 1
|
341
|
+
assert_pairs_match( k, v, 1, 100 )
|
342
|
+
assert_pairs_match( k, v, 2, 200 )
|
343
|
+
assert_pairs_match( k, v, 3, 300 )
|
344
|
+
assert_pairs_match( k, v, 4, 400 )
|
345
|
+
}
|
346
|
+
assert_equal(4, n)
|
347
|
+
|
348
|
+
sumk = n = 0 ; l.array.each_key { |k| n += 1
|
349
|
+
sumk += k
|
350
|
+
assert_equal(k, n)
|
351
|
+
}
|
352
|
+
assert_equal(4, n) ; assert_equal(10, sumk)
|
353
|
+
|
354
|
+
sumv = n = 0 ; l.array.each_ivalue { |v| n += 1
|
355
|
+
sumv += v
|
356
|
+
assert_equal(v, n*100)
|
357
|
+
}
|
358
|
+
assert_equal(4, n) ; assert_equal(1000, sumv)
|
359
|
+
|
360
|
+
# hash assoc iteration
|
361
|
+
l.eval( "hsh = { [1]=100, [2]=200, a=300, b=400, }" )
|
362
|
+
assert_instance_of Lua::Table, l.array
|
363
|
+
n = 0 ; l.hsh.each_pair { |k,v| n += 1
|
364
|
+
assert_pairs_match( k, v, 1, 100 )
|
365
|
+
assert_pairs_match( k, v, 2, 200 )
|
366
|
+
assert_pairs_match( k, v, 'a', 300 )
|
367
|
+
assert_pairs_match( k, v, 'b', 400 )
|
368
|
+
}
|
369
|
+
assert_equal( n, 4)
|
370
|
+
|
371
|
+
n = 0 ; l.hsh.each_key { |k| n += 1
|
372
|
+
assert_pairs_match( n, k, 1, 100 )
|
373
|
+
assert_pairs_match( n, k, 2, 200 )
|
374
|
+
assert_pairs_match( n, k, 3, 'a' )
|
375
|
+
assert_pairs_match( n, k, 4, 'b' )
|
376
|
+
}
|
377
|
+
assert_equal( n, 4)
|
378
|
+
|
379
|
+
n = sumv = 0 ; l.hsh.each_value { |v| n += 1
|
380
|
+
sumv += v
|
381
|
+
}
|
382
|
+
assert_equal(4, n) ; assert_equal( sumv, 1000)
|
383
|
+
|
384
|
+
# done iteration tests
|
385
|
+
assert_luastack_clean l
|
386
|
+
end
|
387
|
+
|
388
|
+
|
389
|
+
# test method dispatch
|
390
|
+
def test_method_dispatch
|
391
|
+
l = Lua::State.new
|
392
|
+
l.eval <<END_OF_LUA
|
393
|
+
str = "a"
|
394
|
+
function uniret() return 1 end
|
395
|
+
function uniret2(a) return a end
|
396
|
+
function multiret() return 1, 2, 3 end
|
397
|
+
function multiret2(a,b) return 1, a, b end
|
398
|
+
|
399
|
+
t = {}
|
400
|
+
t.str = "a"
|
401
|
+
t.uniret = uniret
|
402
|
+
t.uniret2 = uniret2
|
403
|
+
t.multiret = multiret
|
404
|
+
t.multiret2 = multiret2
|
405
|
+
END_OF_LUA
|
406
|
+
|
407
|
+
assert_equal 'a', l.str
|
408
|
+
assert_equal 'a', l.t.str
|
409
|
+
assert_equal 'a', l.str() # ugly, but Ruby
|
410
|
+
assert_equal 'a', l.t.str() # ugly, but Ruby
|
411
|
+
assert_kind_of String, l.str
|
412
|
+
assert_kind_of String, l.t.str
|
413
|
+
assert_raise RuntimeError do l.str_ end
|
414
|
+
assert_raise RuntimeError do l.str! end
|
415
|
+
assert_raise RuntimeError do l.str(2) end
|
416
|
+
|
417
|
+
assert_kind_of Lua::RefObject, l['uniret']
|
418
|
+
assert_kind_of Float, l.uniret
|
419
|
+
assert_kind_of Float, l.uniret_
|
420
|
+
assert_equal 1, l.uniret()
|
421
|
+
assert_equal 1, l.uniret_
|
422
|
+
assert_equal 1, l.t.uniret
|
423
|
+
assert_equal 1, l.t.uniret()
|
424
|
+
assert_equal 2, l.uniret2(2)
|
425
|
+
assert_equal 2, l.t.uniret2(2)
|
426
|
+
r = l.uniret2 2 ; assert_equal 2, r
|
427
|
+
r = l.t.uniret2 2 ; assert_equal 2, r
|
428
|
+
|
429
|
+
assert_equal [1,2,3], l.multiret
|
430
|
+
assert_equal [1,2,3], l.multiret()
|
431
|
+
assert_equal [1,2,3], l.t.multiret
|
432
|
+
assert_equal [1,2,3], l.t.multiret()
|
433
|
+
assert_equal [1,5,6], l.multiret2( 5, 6 )
|
434
|
+
assert_equal [1,5,6], l.t.multiret2( 5, 6 )
|
435
|
+
r = l.multiret2 5, 6 ; assert_equal [1,5,6], r
|
436
|
+
r = l.t.multiret2 5, 6 ; assert_equal [1,5,6], r
|
437
|
+
|
438
|
+
assert_luastack_clean l
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
# test classes
|
443
|
+
def test_classes
|
444
|
+
l = Lua::State.new
|
445
|
+
|
446
|
+
l.eval <<END_LUA
|
447
|
+
Account = {
|
448
|
+
balance = 0,
|
449
|
+
deposit = function( self, v )
|
450
|
+
print "testing testing testing"
|
451
|
+
self.balance = self.balance + v
|
452
|
+
end,
|
453
|
+
}
|
454
|
+
END_LUA
|
455
|
+
assert_equal Lua::Table, l.Account.class
|
456
|
+
assert_equal 0, l.Account.balance
|
457
|
+
assert_nothing_thrown { l.Account.deposit! 100 }
|
458
|
+
assert_equal 100, l.Account.balance
|
459
|
+
# DO WE WANT TO DO ANYTHING LIKE THIS?
|
460
|
+
#assert_nothing_thrown { l.Account.!deposit 50 }
|
461
|
+
#assert_equal 150, l.Account.balance
|
462
|
+
#assert_nothing_thrown { l.Account.!deposit! 25 }
|
463
|
+
#assert_equal 175, l.Account.balance
|
464
|
+
|
465
|
+
assert_luastack_clean l
|
466
|
+
end
|
467
|
+
|
468
|
+
|
469
|
+
# test exceptions
|
470
|
+
def test_exceptions
|
471
|
+
l = Lua::State.new
|
472
|
+
|
473
|
+
assert_raise SyntaxError do
|
474
|
+
l.eval( 'if !exclamation_doesnt_work then return 0 end' )
|
475
|
+
end
|
476
|
+
|
477
|
+
assert_raise RuntimeError do
|
478
|
+
l.eval( 'error("42")' )
|
479
|
+
end
|
480
|
+
|
481
|
+
assert_luastack_clean l
|
482
|
+
end
|
483
|
+
|
484
|
+
# test garbage collection
|
485
|
+
# makes sure various C-based objects are properly cleaned
|
486
|
+
def test_garbage_collection
|
487
|
+
50.times do
|
488
|
+
l = Lua::State.new
|
489
|
+
g = l.__globals
|
490
|
+
l = g = nil
|
491
|
+
GC.start
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
|
496
|
+
# asserts that the state's stack is empty
|
497
|
+
# incorrectly implemented Lua API blocks will trigger this
|
498
|
+
def assert_luastack_clean( lstate )
|
499
|
+
assert_equal 0, lstate.__top
|
500
|
+
end
|
501
|
+
|
502
|
+
# assert that a given key/value pair match an expected key/value pair
|
503
|
+
def assert_pairs_match( key, val, expected_key, expected_val )
|
504
|
+
assert_equal(key, expected_key) if val == expected_val
|
505
|
+
end
|
506
|
+
|
507
|
+
end
|
508
|
+
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: Tamar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Evan Wies, David Love
|
@@ -105,8 +105,8 @@ description: "See: http://rubyluabridge.rubyforge.org"
|
|
105
105
|
email: david@homeunix.org.uk
|
106
106
|
executables: []
|
107
107
|
|
108
|
-
extensions:
|
109
|
-
|
108
|
+
extensions:
|
109
|
+
- src/build/extconf.rb
|
110
110
|
extra_rdoc_files:
|
111
111
|
- LICENSE.txt
|
112
112
|
- README.rdoc
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- Rakefile
|
123
123
|
- Tamar.gemspec
|
124
124
|
- VERSION
|
125
|
+
- src/build/extconf.rb
|
125
126
|
- src/luadist/CMakeLists.txt
|
126
127
|
- src/luadist/COPYRIGHT
|
127
128
|
- src/luadist/README
|
@@ -147,6 +148,29 @@ files:
|
|
147
148
|
- src/luadist/doc/modules/dist.persist.html
|
148
149
|
- src/luadist/doc/modules/dist.sys.html
|
149
150
|
- src/luadist/luadist
|
151
|
+
- src/rubyluabridge/.hg_archival.txt
|
152
|
+
- src/rubyluabridge/.project
|
153
|
+
- src/rubyluabridge/LICENSE
|
154
|
+
- src/rubyluabridge/LUA_IN_RUBY
|
155
|
+
- src/rubyluabridge/README
|
156
|
+
- src/rubyluabridge/RUBY_IN_LUA
|
157
|
+
- src/rubyluabridge/Rakefile
|
158
|
+
- src/rubyluabridge/build/extconf_osx.sh
|
159
|
+
- src/rubyluabridge/build/extconf_ubuntu.sh
|
160
|
+
- src/rubyluabridge/debian/changelog
|
161
|
+
- src/rubyluabridge/debian/compat
|
162
|
+
- src/rubyluabridge/debian/control
|
163
|
+
- src/rubyluabridge/debian/copyright
|
164
|
+
- src/rubyluabridge/debian/libluabridge-ruby1.8.doc-base
|
165
|
+
- src/rubyluabridge/debian/libluabridge-ruby1.8.docs
|
166
|
+
- src/rubyluabridge/debian/libluabridge-ruby1.8.install
|
167
|
+
- src/rubyluabridge/debian/rules
|
168
|
+
- src/rubyluabridge/debian/watch
|
169
|
+
- src/rubyluabridge/doc/jamis.rb
|
170
|
+
- src/rubyluabridge/extconf.rb
|
171
|
+
- src/rubyluabridge/rubyluabridge.cc
|
172
|
+
- src/rubyluabridge/rubyluabridge.h
|
173
|
+
- src/rubyluabridge/tests/lua_in_ruby_test.rb
|
150
174
|
has_rdoc: true
|
151
175
|
homepage: http://rubyluabridge.rubyforge.org
|
152
176
|
licenses:
|
@@ -161,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
185
|
requirements:
|
162
186
|
- - ">="
|
163
187
|
- !ruby/object:Gem::Version
|
164
|
-
hash:
|
188
|
+
hash: 3767394104657576971
|
165
189
|
segments:
|
166
190
|
- 0
|
167
191
|
version: "0"
|