php_vm 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/php_vm/php_vm.c +39 -10
- data/ext/php_vm/php_vm.h +4 -3
- metadata +1 -1
data/ext/php_vm/php_vm.c
CHANGED
@@ -515,7 +515,7 @@ VALUE rb_php_vm_get_class(VALUE cls, VALUE v_class_name)
|
|
515
515
|
return rb_php_class_get(rb_cPHPClass, v_class_name);
|
516
516
|
}
|
517
517
|
|
518
|
-
VALUE
|
518
|
+
VALUE define_global_constants()
|
519
519
|
{
|
520
520
|
TSRMLS_FETCH();
|
521
521
|
|
@@ -567,7 +567,7 @@ VALUE rb_php_vm_define_global_constants(VALUE cls)
|
|
567
567
|
return Qtrue;
|
568
568
|
}
|
569
569
|
|
570
|
-
VALUE
|
570
|
+
VALUE define_global_functions()
|
571
571
|
{
|
572
572
|
TSRMLS_FETCH();
|
573
573
|
|
@@ -606,7 +606,7 @@ VALUE rb_php_vm_define_global_functions(VALUE cls)
|
|
606
606
|
return Qtrue;
|
607
607
|
}
|
608
608
|
|
609
|
-
VALUE
|
609
|
+
VALUE define_global_classes()
|
610
610
|
{
|
611
611
|
TSRMLS_FETCH();
|
612
612
|
|
@@ -638,9 +638,9 @@ VALUE rb_php_vm_define_global_classes(VALUE cls)
|
|
638
638
|
|
639
639
|
VALUE rb_php_vm_define_global(VALUE cls)
|
640
640
|
{
|
641
|
-
VALUE res1 =
|
642
|
-
VALUE res2 =
|
643
|
-
VALUE res3 =
|
641
|
+
VALUE res1 = define_global_constants();
|
642
|
+
VALUE res2 = define_global_functions();
|
643
|
+
VALUE res3 = define_global_classes();
|
644
644
|
return res1==Qtrue && res2==Qtrue && res3==Qtrue;
|
645
645
|
}
|
646
646
|
|
@@ -659,6 +659,37 @@ VALUE rb_php_global_class_call(VALUE self)
|
|
659
659
|
return rb_php_class_get(rb_cPHPClass, callee);
|
660
660
|
}
|
661
661
|
|
662
|
+
VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE self)
|
663
|
+
{
|
664
|
+
int i;
|
665
|
+
|
666
|
+
if (argc==0) {
|
667
|
+
VALUE exception = rb_exc_new2(rb_eArgError, "Too few arguments");
|
668
|
+
rb_exc_raise(exception);
|
669
|
+
}
|
670
|
+
|
671
|
+
// format
|
672
|
+
char *format = malloc(argc*2+1);
|
673
|
+
for (i=0; i<argc; i++) {
|
674
|
+
format[i*2] = '%';
|
675
|
+
format[i*2+1] = 's';
|
676
|
+
}
|
677
|
+
format[i*2] = '\0';
|
678
|
+
|
679
|
+
// argv
|
680
|
+
VALUE *argv2 = malloc(sizeof(VALUE)*(argc+1));
|
681
|
+
argv2[0] = rb_str_new2(format);
|
682
|
+
for (i=0; i<argc; i++) {
|
683
|
+
argv2[i+1] = argv[i];
|
684
|
+
}
|
685
|
+
call_php_method_bridge(NULL, NULL, rb_str_new2("printf"), argc+1, argv2);
|
686
|
+
|
687
|
+
// release
|
688
|
+
free(format);
|
689
|
+
free(argv2);
|
690
|
+
return Qnil;
|
691
|
+
}
|
692
|
+
|
662
693
|
|
663
694
|
// class PHPVM::PHPClass
|
664
695
|
|
@@ -853,15 +884,13 @@ void Init_php_vm()
|
|
853
884
|
rb_define_singleton_method(rb_mPHPVM, "require_once", rb_php_vm_require_once, 1);
|
854
885
|
rb_define_singleton_method(rb_mPHPVM, "exec", rb_php_vm_exec, 1);
|
855
886
|
rb_define_singleton_method(rb_mPHPVM, "get_class", rb_php_vm_get_class, 1);
|
856
|
-
rb_define_singleton_method(rb_mPHPVM, "define_global_constants", rb_php_vm_define_global_constants, 0);
|
857
|
-
rb_define_singleton_method(rb_mPHPVM, "define_global_functions", rb_php_vm_define_global_functions, 0);
|
858
|
-
rb_define_singleton_method(rb_mPHPVM, "define_global_classes", rb_php_vm_define_global_classes, 0);
|
859
887
|
rb_define_singleton_method(rb_mPHPVM, "define_global", rb_php_vm_define_global, 0);
|
860
888
|
|
861
|
-
rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.2.
|
889
|
+
rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.2.3"));
|
862
890
|
|
863
891
|
// module PHPVM::PHPGlobal
|
864
892
|
rb_mPHPGlobal = rb_define_module_under(rb_mPHPVM, "PHPGlobal");
|
893
|
+
rb_define_module_function(rb_mPHPGlobal, "echo", rb_php_global_echo, -1);
|
865
894
|
rb_php_vm_define_global(rb_mPHPVM);
|
866
895
|
|
867
896
|
// class PHPVM::PHPClass
|
data/ext/php_vm/php_vm.h
CHANGED
@@ -45,14 +45,15 @@ extern zval* get_zval(VALUE self);
|
|
45
45
|
extern VALUE rb_php_vm_require(VALUE cls, VALUE rbv_filepath);
|
46
46
|
extern VALUE rb_php_vm_exec(VALUE cls, VALUE rbv_code);
|
47
47
|
extern VALUE rb_php_vm_get_class(VALUE cls, VALUE rbv_class_name);
|
48
|
-
extern VALUE
|
49
|
-
extern VALUE
|
50
|
-
extern VALUE
|
48
|
+
extern VALUE define_global_constants();
|
49
|
+
extern VALUE define_global_functions();
|
50
|
+
extern VALUE define_global_classes();
|
51
51
|
extern VALUE rb_php_vm_define_global(VALUE cls);
|
52
52
|
|
53
53
|
// module PHPVM::PHPGlobal
|
54
54
|
extern VALUE rb_php_global_function_call(int argc, VALUE *argv, VALUE self);
|
55
55
|
extern VALUE rb_php_global_class_call(VALUE self);
|
56
|
+
extern VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE self);
|
56
57
|
|
57
58
|
// class PHPVM::PHPClass
|
58
59
|
extern VALUE rb_php_class_get(VALUE cls, VALUE rbv_name);
|