rua 0.2.6-mswin32 → 0.3.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.txt +4 -1
  2. data/ext/rua.c +211 -27
  3. data/lib/i386-mswin32/rua.so +0 -0
  4. metadata +3 -3
data/README.txt CHANGED
@@ -26,8 +26,9 @@ http://rubyforge.org/frs/?group_id=4845
26
26
 
27
27
  rua = Rua.new(:all)
28
28
  #rua.openlibs(:base, :package, :string)
29
- rua.error_handler = lambda do |e|
29
+ rua.error_handler = lambda do |e, ar|
30
30
  p e
31
+ p ar.to_hash
31
32
  end
32
33
 
33
34
  rua.str = 'xxx'
@@ -85,3 +86,5 @@ http://rubyforge.org/frs/?group_id=4845
85
86
  p co.resume('r')
86
87
  p co.resume('x', 'y')
87
88
  p co.resume('x', 'y')
89
+
90
+ p rua.f.info.to_hash
data/ext/rua.c CHANGED
@@ -16,7 +16,7 @@ __declspec(dllexport) void Init_rua(void);
16
16
 
17
17
  #include "rua.h"
18
18
 
19
- #define VERSION "0.2.6"
19
+ #define VERSION "0.3.0"
20
20
  #define REF_RBOBJ "self"
21
21
 
22
22
  static const char *insecure_methods[] = {
@@ -75,7 +75,7 @@ static const char *insecure_methods[] = {
75
75
  };
76
76
 
77
77
  static const int insecure_method_num = sizeof(insecure_methods) / sizeof(char*);
78
- static VALUE Rua, RuaFunc, RuaThread, RuaError;
78
+ static VALUE Rua, RuaFunc, RuaThread, RuaError, RuaDebug;
79
79
  static VALUE s_all, s_base, s_package, s_string, s_table, s_math, s_io, s_debug;
80
80
 
81
81
  void Init_rua() {
@@ -83,6 +83,7 @@ void Init_rua() {
83
83
  RuaFunc = rb_define_class("RuaFunc", rb_cObject);
84
84
  RuaThread = rb_define_class("RuaThread", rb_cObject);
85
85
  RuaError = rb_define_class("RuaError", rb_eStandardError);
86
+ RuaDebug = rb_define_class("RuaDebug", rb_cObject);
86
87
 
87
88
  rb_define_alloc_func(Rua, rua_alloc);
88
89
  rb_define_const(Rua, "VERSION", rb_str_new2(VERSION));
@@ -100,13 +101,25 @@ void Init_rua() {
100
101
  rb_define_alloc_func(RuaFunc, rua_ref_alloc);
101
102
  rb_define_private_method(RuaFunc, "initialize", rua_func_initialize, 0);
102
103
  rb_define_method(RuaFunc, "call", rua_func_call, -1);
103
- //rb_define_method(RuaFunc, "[]", rua_func_get, 1);
104
- //rb_define_method(RuaFunc, "[]=", rua_func_set, 2);
104
+ rb_define_method(RuaFunc, "info", rua_func_info, 0);
105
105
 
106
106
  rb_define_alloc_func(RuaThread, rua_ref_alloc);
107
107
  rb_define_private_method(RuaThread, "initialize", rua_thread_initialize, 0);
108
108
  rb_define_method(RuaThread, "resume", rua_thread_resume, -1);
109
109
 
110
+ rb_define_alloc_func(RuaDebug, rua_debug_alloc);
111
+ rb_define_private_method(RuaDebug, "initialize", rua_debug_initialize, 0);
112
+ rb_define_method(RuaDebug, "name", rua_debug_name, 0);
113
+ rb_define_method(RuaDebug, "namewhat", rua_debug_namewhat, 0);
114
+ rb_define_method(RuaDebug, "what", rua_debug_what, 0);
115
+ rb_define_method(RuaDebug, "source", rua_debug_source, 0);
116
+ rb_define_method(RuaDebug, "currentline", rua_debug_currentline, 0);
117
+ rb_define_method(RuaDebug, "nups", rua_debug_nups, 0);
118
+ rb_define_method(RuaDebug, "linedefined", rua_debug_linedefined, 0);
119
+ rb_define_method(RuaDebug, "lastlinedefined",rua_debug_lastlinedefined, 0);
120
+ rb_define_method(RuaDebug, "short_src", rua_debug_short_src, 0);
121
+ rb_define_method(RuaDebug, "to_hash", rua_debug_to_hash, 0);
122
+
110
123
  s_all = ID2SYM(rb_intern("all"));
111
124
  s_base = ID2SYM(rb_intern("base"));
112
125
  s_package = ID2SYM(rb_intern("package"));
@@ -145,7 +158,7 @@ static void rua_free(struct rua *p) {
145
158
  free(p);
146
159
  }
147
160
 
148
- /*
161
+ /**
149
162
  * new Rua instance.
150
163
  */
151
164
  static VALUE rua_initialize(int argc, VALUE *argv, VALUE self) {
@@ -164,7 +177,7 @@ static VALUE rua_initialize(int argc, VALUE *argv, VALUE self) {
164
177
  return Qnil;
165
178
  }
166
179
 
167
- /*
180
+ /**
168
181
  * open libraries.
169
182
  * see http://www.lua.org/manual/5.1/manual.html#5.
170
183
  */
@@ -217,7 +230,7 @@ static VALUE rua_openlibs(int argc, VALUE *argv, VALUE self) {
217
230
  return Qnil;
218
231
  }
219
232
 
220
- /*
233
+ /**
221
234
  * evaluates string.
222
235
  */
223
236
  static VALUE rua_eval(VALUE self, VALUE str) {
@@ -239,7 +252,7 @@ static VALUE rua_eval(VALUE self, VALUE str) {
239
252
  return rua_tomultiretval(p->L, pretop, p->R);
240
253
  }
241
254
 
242
- /*
255
+ /**
243
256
  * set global variable.
244
257
  */
245
258
  static VALUE rua_get(VALUE self, VALUE key) {
@@ -253,7 +266,7 @@ static VALUE rua_get(VALUE self, VALUE key) {
253
266
  return retval;
254
267
  }
255
268
 
256
- /*
269
+ /**
257
270
  * set global variable.
258
271
  */
259
272
  static VALUE rua_set(VALUE self, VALUE key, VALUE val) {
@@ -270,7 +283,7 @@ static VALUE rua_set(VALUE self, VALUE key, VALUE val) {
270
283
  return Qnil;
271
284
  }
272
285
 
273
- /*
286
+ /**
274
287
  * get secure flag.
275
288
  */
276
289
  static VALUE rua_get_secure(VALUE self) {
@@ -280,7 +293,7 @@ static VALUE rua_get_secure(VALUE self) {
280
293
  return p->R->secure ? Qtrue : Qfalse;
281
294
  }
282
295
 
283
- /*
296
+ /**
284
297
  * set secure flag.
285
298
  */
286
299
  static VALUE rua_set_secure(VALUE self, VALUE secure) {
@@ -300,7 +313,7 @@ static VALUE rua_set_secure(VALUE self, VALUE secure) {
300
313
  }
301
314
 
302
315
 
303
- /*
316
+ /**
304
317
  * get error handler.
305
318
  */
306
319
  static VALUE rua_get_error_handler(VALUE self) {
@@ -310,7 +323,7 @@ static VALUE rua_get_error_handler(VALUE self) {
310
323
  return p->R->error_handler;
311
324
  }
312
325
 
313
- /*
326
+ /**
314
327
  * set error handler.
315
328
  */
316
329
  static VALUE rua_set_error_handler(VALUE self, VALUE error_handler) {
@@ -325,7 +338,7 @@ static VALUE rua_set_error_handler(VALUE self, VALUE error_handler) {
325
338
  return Qnil;
326
339
  }
327
340
 
328
- /*
341
+ /**
329
342
  * dispatch Rua#[], Rua#[]=.
330
343
  */
331
344
  static VALUE rua_method_missing(int argc, VALUE *argv, VALUE self) {
@@ -375,14 +388,14 @@ static void rua_ref_free(struct rua_ref *p) {
375
388
 
376
389
  // ------------------------------------------------------------------
377
390
 
378
- /*
391
+ /**
379
392
  * new RuaFunc instance.
380
393
  */
381
394
  static VALUE rua_func_initialize(VALUE self) {
382
395
  return Qnil;
383
396
  }
384
397
 
385
- /*
398
+ /**
386
399
  * call Lua function.
387
400
  */
388
401
  static VALUE rua_func_call(int argc, VALUE *argv, VALUE self) {
@@ -407,28 +420,36 @@ static VALUE rua_func_call(int argc, VALUE *argv, VALUE self) {
407
420
  return rua_tomultiretval(p->L, pretop, p->R);
408
421
  }
409
422
 
410
- /*
411
- * set local variable.
423
+ /**
424
+ * get debug info.
412
425
  */
413
- //static VALUE rua_func_get(VALUE self, VALUE key) {
414
- //}
426
+ static VALUE rua_func_info(VALUE self) {
427
+ struct rua_ref *p;
428
+ VALUE ruadebug;
429
+ lua_Debug ar;
415
430
 
416
- /*
417
- * set local variable.
418
- */
419
- //static VALUE rua_func_set(VALUE self, VALUE key, VALUE val) {
420
- //}
431
+ Data_Get_Struct(self, struct rua_ref, p);
432
+ lua_rawgeti(p->L, LUA_REGISTRYINDEX, p->ref);
433
+
434
+ if (lua_isfunction(p->L, -1) && lua_getinfo(p->L, ">nSlu", &ar)) {
435
+ ruadebug = rua_toruadebug(&ar);
436
+ } else {
437
+ ruadebug = Qnil;
438
+ }
439
+
440
+ return ruadebug;
441
+ }
421
442
 
422
443
  // ------------------------------------------------------------------
423
444
 
424
- /*
445
+ /**
425
446
  * new RuaThread instance.
426
447
  */
427
448
  static VALUE rua_thread_initialize(VALUE self) {
428
449
  return Qnil;
429
450
  }
430
451
 
431
- /*
452
+ /**
432
453
  * resume Lua coroutine.
433
454
  */
434
455
  static VALUE rua_thread_resume(int argc, VALUE *argv, VALUE self) {
@@ -461,6 +482,145 @@ static VALUE rua_thread_resume(int argc, VALUE *argv, VALUE self) {
461
482
 
462
483
  // ------------------------------------------------------------------
463
484
 
485
+ static VALUE rua_debug_alloc(VALUE klass) {
486
+ struct rua_debug *p = ALLOC(struct rua_debug);
487
+
488
+ return Data_Wrap_Struct(klass, rua_debug_mark, -1, p);
489
+ }
490
+
491
+ static void rua_debug_mark(struct rua_debug *p) {
492
+ rb_gc_mark(p->name);
493
+ rb_gc_mark(p->namewhat);
494
+ rb_gc_mark(p->what);
495
+ rb_gc_mark(p->source);
496
+ rb_gc_mark(p->currentline);
497
+ rb_gc_mark(p->nups);
498
+ rb_gc_mark(p->linedefined);
499
+ rb_gc_mark(p->lastlinedefined);
500
+ rb_gc_mark(p->short_src);
501
+ }
502
+
503
+ /**
504
+ * new RuaDebug instance.
505
+ * see http://www.lua.org/manual/5.1/manual.html#lua_Debug.
506
+ */
507
+ static VALUE rua_debug_initialize(VALUE self) {
508
+ return Qnil;
509
+ }
510
+
511
+ /**
512
+ * get name.
513
+ */
514
+ static VALUE rua_debug_name(VALUE self) {
515
+ struct rua_debug *p;
516
+
517
+ Data_Get_Struct(self, struct rua_debug, p);
518
+ return p->name;
519
+ }
520
+
521
+ /**
522
+ * get namewhat.
523
+ */
524
+ static VALUE rua_debug_namewhat(VALUE self) {
525
+ struct rua_debug *p;
526
+
527
+ Data_Get_Struct(self, struct rua_debug, p);
528
+ return p->namewhat;
529
+ }
530
+
531
+ /**
532
+ * get what.
533
+ */
534
+ static VALUE rua_debug_what(VALUE self) {
535
+ struct rua_debug *p;
536
+
537
+ Data_Get_Struct(self, struct rua_debug, p);
538
+ return p->what;
539
+ }
540
+
541
+ /**
542
+ * get source.
543
+ */
544
+ static VALUE rua_debug_source(VALUE self) {
545
+ struct rua_debug *p;
546
+
547
+ Data_Get_Struct(self, struct rua_debug, p);
548
+ return p->source;
549
+ }
550
+
551
+ /**
552
+ * get currentline.
553
+ */
554
+ static VALUE rua_debug_currentline(VALUE self) {
555
+ struct rua_debug *p;
556
+
557
+ Data_Get_Struct(self, struct rua_debug, p);
558
+ return p->currentline;
559
+ }
560
+
561
+ /**
562
+ * get nups.
563
+ */
564
+ static VALUE rua_debug_nups(VALUE self) {
565
+ struct rua_debug *p;
566
+
567
+ Data_Get_Struct(self, struct rua_debug, p);
568
+ return p->nups;
569
+ }
570
+
571
+ /**
572
+ * get linedefined.
573
+ */
574
+ static VALUE rua_debug_linedefined(VALUE self) {
575
+ struct rua_debug *p;
576
+
577
+ Data_Get_Struct(self, struct rua_debug, p);
578
+ return p->linedefined;
579
+ }
580
+
581
+ /**
582
+ * get lastlinedefined.
583
+ */
584
+ static VALUE rua_debug_lastlinedefined(VALUE self) {
585
+ struct rua_debug *p;
586
+
587
+ Data_Get_Struct(self, struct rua_debug, p);
588
+ return p->lastlinedefined;
589
+ }
590
+
591
+ /**
592
+ * get short_src.
593
+ */
594
+ static VALUE rua_debug_short_src(VALUE self) {
595
+ struct rua_debug *p;
596
+
597
+ Data_Get_Struct(self, struct rua_debug, p);
598
+ return p->short_src;
599
+ }
600
+
601
+ /**
602
+ * convert to hash.
603
+ */
604
+ static VALUE rua_debug_to_hash(VALUE self) {
605
+ struct rua_debug *p;
606
+ VALUE hash;
607
+
608
+ Data_Get_Struct(self, struct rua_debug, p);
609
+ hash = rb_hash_new();
610
+ rb_hash_aset(hash, ID2SYM(rb_intern("name")) , p->name);
611
+ rb_hash_aset(hash, ID2SYM(rb_intern("namewhat")) , p->namewhat);
612
+ rb_hash_aset(hash, ID2SYM(rb_intern("what")) , p->what);
613
+ rb_hash_aset(hash, ID2SYM(rb_intern("source")) , p->source);
614
+ rb_hash_aset(hash, ID2SYM(rb_intern("currentline")) , p->currentline);
615
+ rb_hash_aset(hash, ID2SYM(rb_intern("nups")) , p->nups);
616
+ rb_hash_aset(hash, ID2SYM(rb_intern("linedefined")) , p->linedefined);
617
+ rb_hash_aset(hash, ID2SYM(rb_intern("lastlinedefined")), p->lastlinedefined);
618
+ rb_hash_aset(hash, ID2SYM(rb_intern("short_src")) , p->short_src);
619
+ return hash;
620
+ }
621
+
622
+ // ------------------------------------------------------------------
623
+
464
624
  static VALUE rua_tomultiretval(lua_State *L, int pretop, struct rua_state *R) {
465
625
  VALUE retval;
466
626
  int nresults, i;
@@ -689,6 +849,7 @@ static int rua_proc_call(lua_State *L) {
689
849
  struct rua_state *R;
690
850
  VALUE proc, args, last, retval, errargs;
691
851
  int i, n, status;
852
+ lua_Debug ar;
692
853
 
693
854
  proc = (VALUE) lua_touserdata(L, lua_upvalueindex(1));
694
855
  R = (struct rua_state *) lua_touserdata(L, lua_upvalueindex(2));
@@ -712,6 +873,11 @@ static int rua_proc_call(lua_State *L) {
712
873
  if (rua_obj_is_executable(R->error_handler)) {
713
874
  errargs = rb_ary_new();
714
875
  rb_ary_push(errargs, ruby_errinfo);
876
+
877
+ if (lua_getstack(L, 0, &ar) && lua_getinfo(L, "nSlu", &ar)) {
878
+ rb_ary_push(errargs, rua_toruadebug(&ar));
879
+ }
880
+
715
881
  rb_ary_push(errargs, R->error_handler);
716
882
  retval = rb_protect(_rua_proc_call, errargs, &status);
717
883
 
@@ -765,6 +931,24 @@ static VALUE rua_toruaobj(VALUE klass, lua_State *L, int idx, struct rua_state *
765
931
  return ruaobj;
766
932
  }
767
933
 
934
+ static VALUE rua_toruadebug(lua_Debug *ar) {
935
+ struct rua_debug *p;
936
+ VALUE ruadebug;
937
+
938
+ ruadebug = rb_funcall(RuaDebug, rb_intern("new"), 0);
939
+ Data_Get_Struct(ruadebug, struct rua_debug, p);
940
+ p->name = ar->name ? rb_str_new2(ar->name) : Qnil;
941
+ p->namewhat = ar->namewhat ? rb_str_new2(ar->namewhat) : Qnil;
942
+ p->what = ar->what ? rb_str_new2(ar->what) : Qnil;
943
+ p->source = ar->source ? rb_str_new2(ar->source) : Qnil;
944
+ p->currentline = INT2NUM(ar->currentline);
945
+ p->nups = INT2NUM(ar->nups);
946
+ p->linedefined = INT2NUM(ar->linedefined);
947
+ p->lastlinedefined = INT2NUM(ar->lastlinedefined);
948
+ p->short_src = ar->short_src ? rb_str_new2(ar->short_src) : Qnil;
949
+ return ruadebug;
950
+ }
951
+
768
952
  static VALUE rua_obj_is_executable(VALUE obj) {
769
953
  return (rb_obj_is_kind_of(obj, rb_cProc) || rb_obj_is_kind_of(obj, rb_cMethod));
770
954
  }
Binary file
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: rua
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.6
7
- date: 2007-11-23 00:00:00 +09:00
6
+ version: 0.3.0
7
+ date: 2007-11-24 00:00:00 +09:00
8
8
  summary: Rua is a library for using Lua under Ruby.
9
9
  require_paths:
10
10
  - lib/i386-mswin32