rlua 1.1.beta1 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ec556f3209b981cdf50de4a9c974907ecd52c4a
4
+ data.tar.gz: f856e079d8d4db09429b7157c212d0bd8bf1fd5f
5
+ SHA512:
6
+ metadata.gz: 46b4c6fb53e006bca7de0c4e1a8b462ca12dbc3d8362852144a50b2f012a1eda0f1975382fb1839e6e5cd31b36a5821b0d7bcbd771489052445a9d7956bebc29
7
+ data.tar.gz: 888fa62dda94679ea12d3f4593d6b908801d4965f4abf3d5476ed5563dea9ee865deeaab74b213cf1f7f0640aa76afa536e57f0312844daa9b7924a6e4aa45bf
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in furnace.gemspec
4
4
  gemspec
5
- gem 'hanna-nouveau'
data/LICENSE.rdoc CHANGED
@@ -1,167 +1,20 @@
1
- .
2
- GNU LESSER GENERAL PUBLIC LICENSE
3
- Version 3, 29 June 2007
4
-
5
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
6
- Everyone is permitted to copy and distribute verbatim copies
7
- of this license document, but changing it is not allowed.
8
-
9
-
10
- This version of the GNU Lesser General Public License incorporates
11
- the terms and conditions of version 3 of the GNU General Public
12
- License, supplemented by the additional permissions listed below.
13
-
14
- 0. Additional Definitions.
15
-
16
- As used herein, "this License" refers to version 3 of the GNU Lesser
17
- General Public License, and the "GNU GPL" refers to version 3 of the GNU
18
- General Public License.
19
-
20
- "The Library" refers to a covered work governed by this License,
21
- other than an Application or a Combined Work as defined below.
22
-
23
- An "Application" is any work that makes use of an interface provided
24
- by the Library, but which is not otherwise based on the Library.
25
- Defining a subclass of a class defined by the Library is deemed a mode
26
- of using an interface provided by the Library.
27
-
28
- A "Combined Work" is a work produced by combining or linking an
29
- Application with the Library. The particular version of the Library
30
- with which the Combined Work was made is also called the "Linked
31
- Version".
32
-
33
- The "Minimal Corresponding Source" for a Combined Work means the
34
- Corresponding Source for the Combined Work, excluding any source code
35
- for portions of the Combined Work that, considered in isolation, are
36
- based on the Application, and not on the Linked Version.
37
-
38
- The "Corresponding Application Code" for a Combined Work means the
39
- object code and/or source code for the Application, including any data
40
- and utility programs needed for reproducing the Combined Work from the
41
- Application, but excluding the System Libraries of the Combined Work.
42
-
43
- 1. Exception to Section 3 of the GNU GPL.
44
-
45
- You may convey a covered work under sections 3 and 4 of this License
46
- without being bound by section 3 of the GNU GPL.
47
-
48
- 2. Conveying Modified Versions.
49
-
50
- If you modify a copy of the Library, and, in your modifications, a
51
- facility refers to a function or data to be supplied by an Application
52
- that uses the facility (other than as an argument passed when the
53
- facility is invoked), then you may convey a copy of the modified
54
- version:
55
-
56
- a) under this License, provided that you make a good faith effort to
57
- ensure that, in the event an Application does not supply the
58
- function or data, the facility still operates, and performs
59
- whatever part of its purpose remains meaningful, or
60
-
61
- b) under the GNU GPL, with none of the additional permissions of
62
- this License applicable to that copy.
63
-
64
- 3. Object Code Incorporating Material from Library Header Files.
65
-
66
- The object code form of an Application may incorporate material from
67
- a header file that is part of the Library. You may convey such object
68
- code under terms of your choice, provided that, if the incorporated
69
- material is not limited to numerical parameters, data structure
70
- layouts and accessors, or small macros, inline functions and templates
71
- (ten or fewer lines in length), you do both of the following:
72
-
73
- a) Give prominent notice with each copy of the object code that the
74
- Library is used in it and that the Library and its use are
75
- covered by this License.
76
-
77
- b) Accompany the object code with a copy of the GNU GPL and this license
78
- document.
79
-
80
- 4. Combined Works.
81
-
82
- You may convey a Combined Work under terms of your choice that,
83
- taken together, effectively do not restrict modification of the
84
- portions of the Library contained in the Combined Work and reverse
85
- engineering for debugging such modifications, if you also do each of
86
- the following:
87
-
88
- a) Give prominent notice with each copy of the Combined Work that
89
- the Library is used in it and that the Library and its use are
90
- covered by this License.
91
-
92
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
93
- document.
94
-
95
- c) For a Combined Work that displays copyright notices during
96
- execution, include the copyright notice for the Library among
97
- these notices, as well as a reference directing the user to the
98
- copies of the GNU GPL and this license document.
99
-
100
- d) Do one of the following:
101
-
102
- 0) Convey the Minimal Corresponding Source under the terms of this
103
- License, and the Corresponding Application Code in a form
104
- suitable for, and under terms that permit, the user to
105
- recombine or relink the Application with a modified version of
106
- the Linked Version to produce a modified Combined Work, in the
107
- manner specified by section 6 of the GNU GPL for conveying
108
- Corresponding Source.
109
-
110
- 1) Use a suitable shared library mechanism for linking with the
111
- Library. A suitable mechanism is one that (a) uses at run time
112
- a copy of the Library already present on the user's computer
113
- system, and (b) will operate properly with a modified version
114
- of the Library that is interface-compatible with the Linked
115
- Version.
116
-
117
- e) Provide Installation Information, but only if you would otherwise
118
- be required to provide such information under section 6 of the
119
- GNU GPL, and only to the extent that such information is
120
- necessary to install and execute a modified version of the
121
- Combined Work produced by recombining or relinking the
122
- Application with a modified version of the Linked Version. (If
123
- you use option 4d0, the Installation Information must accompany
124
- the Minimal Corresponding Source and Corresponding Application
125
- Code. If you use option 4d1, you must provide the Installation
126
- Information in the manner specified by section 6 of the GNU GPL
127
- for conveying Corresponding Source.)
128
-
129
- 5. Combined Libraries.
130
-
131
- You may place library facilities that are a work based on the
132
- Library side by side in a single library together with other library
133
- facilities that are not Applications and are not covered by this
134
- License, and convey such a combined library under terms of your
135
- choice, if you do both of the following:
136
-
137
- a) Accompany the combined library with a copy of the same work based
138
- on the Library, uncombined with any other library facilities,
139
- conveyed under the terms of this License.
140
-
141
- b) Give prominent notice with the combined library that part of it
142
- is a work based on the Library, and explaining where to find the
143
- accompanying uncombined form of the same work.
144
-
145
- 6. Revised Versions of the GNU Lesser General Public License.
146
-
147
- The Free Software Foundation may publish revised and/or new versions
148
- of the GNU Lesser General Public License from time to time. Such new
149
- versions will be similar in spirit to the present version, but may
150
- differ in detail to address new problems or concerns.
151
-
152
- Each version is given a distinguishing version number. If the
153
- Library as you received it specifies that a certain numbered version
154
- of the GNU Lesser General Public License "or any later version"
155
- applies to it, you have the option of following the terms and
156
- conditions either of that published version or of any later version
157
- published by the Free Software Foundation. If the Library as you
158
- received it does not specify a version number of the GNU Lesser
159
- General Public License, you may choose any version of the GNU Lesser
160
- General Public License ever published by the Free Software Foundation.
161
-
162
- If the Library as you received it specifies that a proxy can decide
163
- whether future versions of the GNU Lesser General Public License shall
164
- apply, that proxy's public statement of acceptance of any version is
165
- permanent authorization for you to choose that version for the
166
- Library.
167
-
1
+ Copyright (c) 2009-2012 Peter Zotov <whitequark@whitequark.org>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -3,7 +3,7 @@ RLua is Ruby to Lua bindings library that features nearly complete coverage of L
3
3
  C API, seamless translation of Lua and Ruby objects into each other, calling Lua
4
4
  functions from Ruby and vice versa.
5
5
 
6
- RLua currently uses Lua 5.1, and is Ruby 1.8.7 and 1.9.x compatible.
6
+ RLua currently uses Lua 5.1, and is Ruby 1.9+ compatible.
7
7
 
8
8
  = Installation
9
9
  RLua is distributed as gem package through rubygems.org, so the procedure is
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
  require 'rdoc/task'
3
4
 
5
+ RSpec::Core::RakeTask.new(:test)
6
+
4
7
  Rake::RDocTask.new do |rd|
5
8
  rd.main = 'README.rdoc'
6
9
  rd.title = 'RLua Documentation'
data/ext/extconf.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "mkmf"
2
2
 
3
+ $CFLAGS += " -Wno-declaration-after-statement"
4
+
3
5
  dir_config('lua5.1')
4
6
 
5
7
  unless have_library('lua5.1', 'luaL_newstate') or have_library('lua.5.1', 'luaL_newstate')
data/ext/rlua.c CHANGED
@@ -1,25 +1,9 @@
1
- /*
2
- * This file is part of RLua.
3
- *
4
- * RLua is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU Lesser General Public License as
6
- * published by the Free Software Foundation, either version 3 of
7
- * the License, or (at your option) any later version.
8
- *
9
- * RLua is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU Lesser General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU Lesser General Public
15
- * License along with RLua. If not, see <http://www.gnu.org/licenses/>.
16
- */
17
-
18
- #include <ruby.h>
19
- #include <lua.h>
20
- #include <lauxlib.h>
21
- #include <lualib.h>
1
+ #include <ruby.h>
2
+ #include <lua5.1/lua.h>
3
+ #include <lua5.1/lauxlib.h>
4
+ #include <lua5.1/lualib.h>
22
5
  #include <ctype.h>
6
+ #include <ruby/encoding.h>
23
7
 
24
8
  VALUE mLua, cLuaState, cLuaMultret, cLuaFunction, cLuaTable;
25
9
 
@@ -39,15 +23,15 @@ static VALUE rlua_finalize_ref(VALUE id, VALUE rbState)
39
23
  {
40
24
  lua_State* state;
41
25
  Data_Get_Struct(rbState, lua_State, state);
42
-
26
+
43
27
  int ref = FIX2INT(rb_hash_aref(rb_iv_get(rbState, "@refs"), id));
44
-
28
+
45
29
  lua_getfield(state, LUA_REGISTRYINDEX, "rlua");
46
30
  luaL_unref(state, -1, ref);
47
31
  lua_pop(state, 1);
48
-
32
+
49
33
  rb_hash_delete(rb_iv_get(rbState, "@refs"), id);
50
-
34
+
51
35
  return Qnil;
52
36
  }
53
37
 
@@ -83,7 +67,7 @@ static VALUE rlua_get_var(lua_State *state)
83
67
  case LUA_TLIGHTUSERDATA:
84
68
  rb_warn("cannot pop LUA_TLIGHTUSERDATA");
85
69
  return Qnil;
86
-
70
+
87
71
  case LUA_TBOOLEAN:
88
72
  return lua_toboolean(state, -1) ? Qtrue : Qfalse;
89
73
 
@@ -94,7 +78,7 @@ static VALUE rlua_get_var(lua_State *state)
94
78
  size_t length;
95
79
  const char* string;
96
80
  string = lua_tolstring(state, -1, &length);
97
- return rb_str_new(string, length);
81
+ return rb_enc_str_new(string, length, rb_default_external_encoding());
98
82
  }
99
83
 
100
84
  case LUA_TTABLE:
@@ -115,17 +99,18 @@ static void rlua_push_var(lua_State *state, VALUE value)
115
99
  lua_pushnil(state);
116
100
  break;
117
101
 
118
- case T_STRING:
119
- lua_pushlstring(state, RSTRING_PTR(value), RSTRING_LEN(value));
102
+ case T_STRING: {
103
+ VALUE string = rb_str_export_to_enc(value, rb_default_external_encoding());
104
+ lua_pushlstring(state, RSTRING_PTR(string), RSTRING_LEN(string));
120
105
  break;
121
-
106
+ }
122
107
  case T_FIXNUM:
123
- lua_pushnumber(state, FIX2INT(value));
108
+ lua_pushnumber(state, FIX2INT(value));
124
109
  break;
125
110
 
126
111
  case T_BIGNUM:
127
112
  case T_FLOAT:
128
- lua_pushnumber(state, NUM2DBL(value));
113
+ lua_pushnumber(state, NUM2DBL(value));
129
114
  break;
130
115
 
131
116
  case T_ARRAY: {
@@ -200,7 +185,7 @@ static void rlua_load_string(lua_State* state, VALUE code, VALUE chunkname)
200
185
 
201
186
  // do not interfere with users' string
202
187
  VALUE interm_code = rb_str_new3(code);
203
-
188
+
204
189
  int retval = lua_load(state, rlua_reader, (void*) interm_code, RSTRING_PTR(chunkname));
205
190
  if(retval != 0) {
206
191
  size_t errlen;
@@ -219,14 +204,14 @@ static VALUE rlua_pcall(lua_State* state, int argc)
219
204
  // stack: |argN-arg1|func|...
220
205
  // <N pts.> <1>
221
206
  int base = lua_gettop(state) - 1 - argc;
222
-
207
+
223
208
  int retval = lua_pcall(state, argc, LUA_MULTRET, 0);
224
209
  if(retval != 0) {
225
210
  size_t errlen;
226
211
  const char* errstr = lua_tolstring(state, -1, &errlen);
227
212
  VALUE error = rb_str_new(errstr, errlen);
228
213
  lua_pop(state, 1);
229
-
214
+
230
215
  if(retval == LUA_ERRRUN)
231
216
  rb_exc_raise(rb_exc_new3(rb_eRuntimeError, error));
232
217
  else if(retval == LUA_ERRSYNTAX)
@@ -260,7 +245,7 @@ static VALUE rbLuaTable_initialize(int argc, VALUE* argv, VALUE self)
260
245
  {
261
246
  VALUE rbLuaState, ref;
262
247
  rb_scan_args(argc, argv, "11", &rbLuaState, &ref);
263
-
248
+
264
249
  VALUE stateSource = rb_obj_class(rbLuaState);
265
250
  if(stateSource != cLuaState && stateSource != cLuaTable && stateSource != cLuaFunction)
266
251
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Lua::State, Lua::Table or Lua::Function)",
@@ -268,22 +253,22 @@ static VALUE rbLuaTable_initialize(int argc, VALUE* argv, VALUE self)
268
253
 
269
254
  VALUE rbState = rb_iv_get(rbLuaState, "@state");
270
255
  rb_iv_set(self, "@state", rbState);
271
-
256
+
272
257
  if(ref == Qnil) {
273
258
  lua_State* state;
274
259
  Data_Get_Struct(rbState, lua_State, state);
275
-
260
+
276
261
  lua_newtable(state);
277
262
  ref = rlua_makeref(state);
278
263
  lua_pop(state, 1);
279
264
  } else if(TYPE(ref) != T_FIXNUM) {
280
265
  rb_raise(rb_eTypeError, "wrong argument type %s (expected nil)", rb_obj_classname(ref));
281
266
  }
282
-
267
+
283
268
  rlua_add_ref_finalizer(rbState, ref, self);
284
269
 
285
270
  rb_iv_set(self, "@ref", ref);
286
-
271
+
287
272
  return self;
288
273
  }
289
274
 
@@ -301,9 +286,9 @@ static VALUE rbLuaTable_next(VALUE self, VALUE table, VALUE index)
301
286
  {
302
287
  lua_State* state;
303
288
  Data_Get_Struct(rb_iv_get(table, "@state"), lua_State, state);
304
-
289
+
305
290
  VALUE retval;
306
-
291
+
307
292
  rlua_push_var(state, table); // stack: |this|...
308
293
  rlua_push_var(state, index); // |indx|this|...
309
294
  if(lua_next(state, -2) != 0) { // |valu|key |this|...
@@ -312,7 +297,7 @@ static VALUE rbLuaTable_next(VALUE self, VALUE table, VALUE index)
312
297
  lua_pop(state, 1); // |key |this|...
313
298
  key = rlua_get_var(state); // |key |this|...
314
299
  lua_pop(state, 2); // ...
315
-
300
+
316
301
  retval = rb_ary_new();
317
302
  rb_ary_push(retval, key);
318
303
  rb_ary_push(retval, value);
@@ -320,7 +305,7 @@ static VALUE rbLuaTable_next(VALUE self, VALUE table, VALUE index)
320
305
  retval = Qnil;
321
306
  lua_pop(state, 1); // ...
322
307
  }
323
-
308
+
324
309
  return retval;
325
310
  }
326
311
 
@@ -334,14 +319,14 @@ static VALUE rbLuaTable_get(VALUE self, VALUE index)
334
319
  {
335
320
  lua_State* state;
336
321
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
337
-
322
+
338
323
  VALUE value;
339
324
  rlua_push_var(state, self); // stack: |this|...
340
325
  rlua_push_var(state, index); // |indx|this|...
341
326
  lua_gettable(state, -2); // |valu|this|...
342
327
  value = rlua_get_var(state); // |valu|this|...
343
328
  lua_pop(state, 2); // ...
344
-
329
+
345
330
  return value;
346
331
  }
347
332
 
@@ -375,14 +360,14 @@ static VALUE rbLuaTable_rawget(VALUE self, VALUE index)
375
360
  {
376
361
  lua_State* state;
377
362
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
378
-
363
+
379
364
  VALUE value;
380
365
  rlua_push_var(state, self); // stack: |this|...
381
366
  rlua_push_var(state, index); // |indx|this|...
382
367
  lua_rawget(state, -2); // |valu|this|...
383
368
  value = rlua_get_var(state); // |valu|this|...
384
369
  lua_pop(state, 2); // ...
385
-
370
+
386
371
  return value;
387
372
  }
388
373
 
@@ -417,12 +402,12 @@ static VALUE rbLuaTable_length(VALUE self)
417
402
  {
418
403
  lua_State* state;
419
404
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
420
-
405
+
421
406
  VALUE length;
422
407
  rlua_push_var(state, self); // stack: |this|...
423
408
  length = INT2FIX(lua_objlen(state, -1));
424
409
  lua_pop(state, 1); // ...
425
-
410
+
426
411
  return length;
427
412
  }
428
413
 
@@ -459,17 +444,17 @@ static VALUE rbLuaTable_method_missing(int argc, VALUE* argv, VALUE self)
459
444
  rb_scan_args(argc, argv, "1*", &id, &args);
460
445
 
461
446
  VALUE name = rb_str_new2(rb_id2name(rb_to_id(id)));
462
-
447
+
463
448
  int is_method = 0;
464
449
  int is_assign = 0;
465
450
  if(RSTRING_PTR(name)[RSTRING_LEN(name) - 1] == '!')
466
451
  is_method = 1;
467
452
  if(RSTRING_PTR(name)[RSTRING_LEN(name) - 1] == '=')
468
453
  is_assign = 1;
469
-
454
+
470
455
  if(is_method || is_assign)
471
456
  rb_str_resize(name, RSTRING_LEN(name) - 1);
472
-
457
+
473
458
  if(is_assign) {
474
459
  VALUE value;
475
460
  rb_scan_args(argc, argv, "11", &id, &value);
@@ -495,24 +480,24 @@ static int call_ruby_proc(lua_State* state)
495
480
  int i;
496
481
  int argc = lua_gettop(state);
497
482
  VALUE proc, args;
498
-
483
+
499
484
  proc = (VALUE) lua_touserdata(state, lua_upvalueindex(1));
500
485
  args = rb_ary_new();
501
-
486
+
502
487
  for(i = 0; i < argc; i++) {
503
488
  rb_ary_unshift(args, rlua_get_var(state));
504
489
  lua_pop(state, 1);
505
490
  }
506
-
491
+
507
492
  VALUE retval = rb_apply(proc, rb_intern("call"), args);
508
-
493
+
509
494
  if(rb_obj_class(retval) == cLuaMultret) {
510
495
  VALUE array = rb_iv_get(retval, "@args");
511
496
  int i;
512
-
497
+
513
498
  for(i = 0; i < RARRAY_LEN(array); i++)
514
499
  rlua_push_var(state, RARRAY_PTR(array)[i]);
515
-
500
+
516
501
  return RARRAY_LEN(array);
517
502
  } else {
518
503
  rlua_push_var(state, retval);
@@ -532,18 +517,18 @@ static VALUE rbLuaFunction_initialize(int argc, VALUE* argv, VALUE self)
532
517
  {
533
518
  VALUE rbLuaState, ref = Qnil, func;
534
519
  rb_scan_args(argc, argv, "11", &rbLuaState, &func);
535
-
520
+
536
521
  if(rb_obj_class(rbLuaState) != cLuaState)
537
522
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Lua::State)", rb_obj_classname(rbLuaState));
538
-
523
+
539
524
  VALUE rbState = rb_iv_get(rbLuaState, "@state");
540
525
  rb_iv_set(self, "@state", rbState);
541
-
526
+
542
527
  lua_State* state;
543
528
  Data_Get_Struct(rbState, lua_State, state);
544
-
529
+
545
530
  VALUE proc = Qnil;
546
-
531
+
547
532
  if(TYPE(func) == T_FIXNUM)
548
533
  ref = func;
549
534
  else if(rb_respond_to(func, rb_intern("call")))
@@ -556,15 +541,15 @@ static VALUE rbLuaFunction_initialize(int argc, VALUE* argv, VALUE self)
556
541
  lua_pushcclosure(state, call_ruby_proc, 1);
557
542
  ref = rlua_makeref(state);
558
543
  lua_pop(state, 1);
559
-
544
+
560
545
  // don't allow GC to collect proc
561
546
  rb_iv_set(self, "@proc", proc);
562
547
  }
563
-
548
+
564
549
  rlua_add_ref_finalizer(rbState, ref, self);
565
550
 
566
551
  rb_iv_set(self, "@ref", ref);
567
-
552
+
568
553
  return self;
569
554
  }
570
555
 
@@ -636,19 +621,19 @@ static VALUE rbLuaFunction_call(VALUE self, VALUE args)
636
621
  static VALUE rbLua_initialize(VALUE self)
637
622
  {
638
623
  lua_State* state = luaL_newstate();
639
-
624
+
640
625
  VALUE rbState = Data_Wrap_Struct(rb_cObject, 0, lua_close, state);
641
626
  rb_iv_set(self, "@state", rbState);
642
-
627
+
643
628
  lua_pushlightuserdata(state, (void*) self);
644
629
  lua_setfield(state, LUA_REGISTRYINDEX, "rlua_state");
645
-
630
+
646
631
  lua_newtable(state);
647
632
  lua_setfield(state, LUA_REGISTRYINDEX, "rlua");
648
-
633
+
649
634
  rb_iv_set(rbState, "@refs", rb_hash_new());
650
635
  rb_iv_set(rbState, "@procs", rb_ary_new());
651
-
636
+
652
637
  return self;
653
638
  }
654
639
 
@@ -671,12 +656,12 @@ static VALUE rbLua_eval(int argc, VALUE* argv, VALUE self)
671
656
 
672
657
  lua_State* state;
673
658
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
674
-
659
+
675
660
  if(chunkname == Qnil)
676
661
  chunkname = rb_str_new2("=<eval>");
677
662
 
678
663
  rlua_load_string(state, code, chunkname);
679
-
664
+
680
665
  return rlua_pcall(state, 0);
681
666
  }
682
667
 
@@ -689,7 +674,7 @@ static VALUE rbLua_get_env(VALUE self)
689
674
  {
690
675
  lua_State* state;
691
676
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
692
-
677
+
693
678
  VALUE ref;
694
679
  rlua_push_var(state, self); // stack: |this|...
695
680
  lua_getfenv(state, -1); // |envi|this|...
@@ -709,7 +694,7 @@ static VALUE rbLua_set_env(VALUE self, VALUE env)
709
694
  {
710
695
  lua_State* state;
711
696
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
712
-
697
+
713
698
  if(rb_obj_class(env) != cLuaTable && TYPE(env) != T_HASH)
714
699
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Lua::Table or Hash)", rb_obj_classname(env));
715
700
 
@@ -717,7 +702,7 @@ static VALUE rbLua_set_env(VALUE self, VALUE env)
717
702
  rlua_push_var(state, env); // |envi|this|...
718
703
  lua_setfenv(state, -2); // |this|...
719
704
  lua_pop(state, 1); // ...
720
-
705
+
721
706
  return env;
722
707
  }
723
708
 
@@ -732,16 +717,16 @@ static VALUE rbLua_get_metatable(VALUE self, VALUE object)
732
717
  {
733
718
  lua_State* state;
734
719
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
735
-
720
+
736
721
  rlua_push_var(state, object); // stack: |objt|...
737
722
  if(lua_getmetatable(state, -1)) { // |meta|objt|...
738
723
  VALUE ref = rlua_makeref(state); // |meta|objt|...
739
724
  lua_pop(state, 2); // ...
740
-
725
+
741
726
  return rb_funcall(cLuaTable, rb_intern("new"), 2, self, ref);
742
727
  } else { // |objt|...
743
728
  lua_pop(state, 1); // ...
744
-
729
+
745
730
  return Qnil;
746
731
  }
747
732
  }
@@ -762,7 +747,7 @@ static VALUE rbLua_set_metatable(VALUE self, VALUE object, VALUE metatable)
762
747
  {
763
748
  lua_State* state;
764
749
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
765
-
750
+
766
751
  if(rb_obj_class(metatable) != cLuaTable && TYPE(metatable) != T_HASH)
767
752
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Lua::Table or Hash)", rb_obj_classname(metatable));
768
753
 
@@ -770,7 +755,7 @@ static VALUE rbLua_set_metatable(VALUE self, VALUE object, VALUE metatable)
770
755
  rlua_push_var(state, metatable); // |meta|objt|...
771
756
  lua_setmetatable(state, -2); // |objt|...
772
757
  lua_pop(state, 1); // ...
773
-
758
+
774
759
  return metatable;
775
760
  }
776
761
 
@@ -1053,7 +1038,7 @@ static int bootstrap_xpcall (lua_State *L) {
1053
1038
  }
1054
1039
 
1055
1040
  static const
1056
- struct { char* name; lua_CFunction func; }
1041
+ struct { const char* name; lua_CFunction func; }
1057
1042
  stdlib[] = {
1058
1043
  { "type", bootstrap_type },
1059
1044
  { "next", bootstrap_next },
@@ -1086,21 +1071,20 @@ static VALUE rbLua_bootstrap(VALUE self)
1086
1071
  {
1087
1072
  lua_State* state;
1088
1073
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
1089
-
1090
- int nf;
1091
- for(nf = 0; nf < sizeof(stdlib) / sizeof(stdlib[0]); nf++) {
1074
+
1075
+ for(size_t nf = 0; nf < sizeof(stdlib) / sizeof(stdlib[0]); nf++) {
1092
1076
  lua_pushcclosure(state, stdlib[nf].func, 0);
1093
1077
  lua_setglobal(state, stdlib[nf].name);
1094
1078
  }
1095
-
1079
+
1096
1080
  lua_pushcfunction(state, bootstrap_next);
1097
1081
  lua_pushcclosure(state, bootstrap_pairs, 1);
1098
1082
  lua_setglobal(state, "pairs");
1099
-
1083
+
1100
1084
  lua_pushcfunction(state, bootstrap_inext);
1101
1085
  lua_pushcclosure(state, bootstrap_ipairs, 1);
1102
1086
  lua_setglobal(state, "ipairs");
1103
-
1087
+
1104
1088
  return Qtrue;
1105
1089
  }
1106
1090
 
@@ -1140,7 +1124,7 @@ static VALUE rbLua_load_stdlib(VALUE self, VALUE args)
1140
1124
  {
1141
1125
  lua_State* state;
1142
1126
  Data_Get_Struct(rb_iv_get(self, "@state"), lua_State, state);
1143
-
1127
+
1144
1128
  if(rb_ary_includes(args, ID2SYM(rb_intern("all")))) {
1145
1129
  luaL_openlibs(state);
1146
1130
  } else {
@@ -1161,7 +1145,7 @@ static VALUE rbLua_load_stdlib(VALUE self, VALUE args)
1161
1145
  if(rb_ary_includes(args, ID2SYM(rb_intern(LUA_LOADLIBNAME))))
1162
1146
  rlua_openlib(state, luaopen_package);
1163
1147
  }
1164
-
1148
+
1165
1149
  return Qtrue;
1166
1150
  }
1167
1151
 
@@ -1171,7 +1155,7 @@ void Init_rlua()
1171
1155
  * Main module that encapsulates all RLua classes and methods.
1172
1156
  */
1173
1157
  mLua = rb_define_module("Lua");
1174
-
1158
+
1175
1159
  /*
1176
1160
  * Lua::State represents Lua interpreter state which is one thread of
1177
1161
  * execution.
data/lib/rlua.rb CHANGED
@@ -1,18 +1,3 @@
1
- # This file is part of RLua.
2
- #
3
- # RLua is free software: you can redistribute it and/or modify
4
- # it under the terms of the GNU Lesser General Public License as
5
- # published by the Free Software Foundation, either version 3 of
6
- # the License, or (at your option) any later version.
7
- #
8
- # RLua is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- # GNU Lesser General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU Lesser General Public
14
- # License along with RLua. If not, see <http://www.gnu.org/licenses/>.
15
-
16
1
  require 'rlua.so'
17
2
 
18
3
  module Lua
data/rlua.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "rlua"
3
- gem.version = '1.1.beta1'
4
- gem.authors = ["Peter Zotov"]
3
+ gem.version = '1.1'
4
+ gem.authors = ["whitequark"]
5
5
  gem.email = ["whitequark@whitequark.org"]
6
6
  gem.description = %q{Ruby to Lua bindings}
7
7
  gem.summary = <<-EOD
@@ -10,15 +10,21 @@ Gem::Specification.new do |gem|
10
10
  code of each language from other one.
11
11
  EOD
12
12
  gem.homepage = "http://whitequark.github.com/rlua/"
13
+ gem.license = "MIT"
13
14
 
14
15
  gem.files = `git ls-files`.split($/)
15
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
18
  gem.require_paths = ["lib"]
19
+ gem.extensions = ['ext/extconf.rb']
20
+
21
+ gem.required_ruby_version = '>= 1.9.3'
22
+ gem.requirements << 'liblua 5.1'
18
23
 
19
24
  gem.add_development_dependency 'rdoc'
20
25
  gem.add_development_dependency 'rake'
21
26
  gem.add_development_dependency 'hanna-nouveau'
27
+ gem.add_development_dependency 'rspec'
22
28
 
23
29
  gem.extra_rdoc_files = Dir['*.rdoc', 'ext/*.c'].to_a
24
30
  gem.rdoc_options = ['--main=README.rdoc', '--title=RLua Documentation']
data/spec/rlua_spec.rb ADDED
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+ require 'rlua'
3
+
4
+ describe Lua::State do
5
+ context 'ruby' do
6
+ it 'creates a variable in Ruby and pass it to Lua' do
7
+ subject.value = 10
8
+
9
+ subject.__eval 'value = value * 2'
10
+
11
+ expect(subject.value).to eq 20
12
+ end
13
+
14
+ it 'creates a table in Ruby and pass it to Lua' do
15
+ subject.ruby = {
16
+ 'meaning_of_life' => 42,
17
+ 'zaphod' => lambda { |table| p "Meaning of life: #{table.meaning_of_life}" }
18
+ }
19
+
20
+ expect { subject.__eval "ruby:zaphod()" }.to output("\"Meaning of life: 42.0\"\n").to_stdout
21
+ end
22
+ end
23
+
24
+ describe 'lua' do
25
+ it 'creates a variable in Lua and pass it to Ruby' do
26
+ subject.__eval 'value = 15'
27
+
28
+ expect(subject.value).to eq 15
29
+ end
30
+
31
+ it 'creates a function in Lua and launch it from Ruby' do
32
+ subject.__eval "ran = false"
33
+ subject.__eval "function lua_func() ran = true end"
34
+
35
+ expect(subject.ran).to be_falsey
36
+
37
+ subject.lua_func
38
+
39
+ expect(subject.ran).to be_truthy
40
+ end
41
+
42
+ context 'string encoding' do
43
+ before { Encoding.default_external = Encoding::UTF_8 }
44
+
45
+ it 'creates a string in Lua and pass it to Ruby with default_external encoding' do
46
+ subject.__eval 'value = "höhöhö"'
47
+
48
+ expect(subject.value).to eq 'höhöhö'
49
+ expect(subject.value.encoding).to eq Encoding::UTF_8
50
+ end
51
+
52
+ it 'creates a string in Lua and pass it to Ruby with custom default_external encoding' do
53
+ Encoding.default_external = Encoding::ISO8859_15
54
+
55
+ subject.__eval 'value = "höhöhö"'.encode(Encoding::ISO8859_15)
56
+
57
+ expect(subject.value).to eq 'höhöhö'.encode(Encoding::ISO8859_15)
58
+ expect(subject.value.encoding).to eq Encoding::ISO8859_15
59
+ end
60
+
61
+ it 'creates a string in Lua and pass it to Ruby with default_external encoding' do
62
+ subject.value = 'höhöhö'.encode(Encoding::EUCJP_MS)
63
+
64
+ expect(subject.value).to eq 'höhöhö'
65
+ expect(subject.value.encoding).to eq Encoding.default_external
66
+ end
67
+ end
68
+
69
+ end
70
+ end
metadata CHANGED
@@ -1,76 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rlua
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.beta1
5
- prerelease: 4
4
+ version: '1.1'
6
5
  platform: ruby
7
6
  authors:
8
- - Peter Zotov
7
+ - whitequark
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-07 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rdoc
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: hanna-nouveau
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  description: Ruby to Lua bindings
63
70
  email:
64
71
  - whitequark@whitequark.org
65
72
  executables: []
66
- extensions: []
73
+ extensions:
74
+ - ext/extconf.rb
67
75
  extra_rdoc_files:
68
- - README.rdoc
69
76
  - LICENSE.rdoc
70
77
  - TODO.rdoc
78
+ - README.rdoc
71
79
  - ext/rlua.c
72
80
  files:
73
- - .gitignore
81
+ - ".gitignore"
74
82
  - Gemfile
75
83
  - LICENSE.rdoc
76
84
  - README.rdoc
@@ -80,35 +88,36 @@ files:
80
88
  - ext/rlua.c
81
89
  - lib/rlua.rb
82
90
  - rlua.gemspec
91
+ - spec/rlua_spec.rb
83
92
  homepage: http://whitequark.github.com/rlua/
84
- licenses: []
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
85
96
  post_install_message:
86
97
  rdoc_options:
87
- - --main=README.rdoc
88
- - --title=RLua Documentation
98
+ - "--main=README.rdoc"
99
+ - "--title=RLua Documentation"
89
100
  require_paths:
90
101
  - lib
91
102
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
103
  requirements:
94
- - - ! '>='
104
+ - - ">="
95
105
  - !ruby/object:Gem::Version
96
- version: '0'
97
- segments:
98
- - 0
99
- hash: 3158014571004423485
106
+ version: 1.9.3
100
107
  required_rubygems_version: !ruby/object:Gem::Requirement
101
- none: false
102
108
  requirements:
103
- - - ! '>'
109
+ - - ">="
104
110
  - !ruby/object:Gem::Version
105
- version: 1.3.1
106
- requirements: []
111
+ version: '0'
112
+ requirements:
113
+ - liblua 5.1
107
114
  rubyforge_project:
108
- rubygems_version: 1.8.24
115
+ rubygems_version: 2.5.1
109
116
  signing_key:
110
- specification_version: 3
117
+ specification_version: 4
111
118
  summary: Fully functional, almost complete Ruby to Lua binding library that features
112
119
  seamless translation of most Lua and Ruby objects and calling code of each language
113
120
  from other one.
114
- test_files: []
121
+ test_files:
122
+ - spec/rlua_spec.rb
123
+ has_rdoc: