Menu

[r63]: / trunk / lang / python / python.interface.php  Maximize  Restore  History

Download this file

98 lines (76 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
trait lang_python_interface {
public static function python_command($cmd,$parms) {
switch($cmd) {
case "print": echo $parms; break;
}
}
public static function python_for() {
echo "START-FOR";
}
public static function python_for_end() {
echo "END-FOR";
}
public static function python_list($v) {
echo "List: ";
var_dump($v);
return 1;
}
public static function python_mod($a,$b){return is_integer($a)?$a%$b:$a;}
public static function python_class($a) {
static::$state = 'class';
static::$class = array(
'name' => $a->name,
);
}
public static function python_class_end() {
$classname = static::$class['name'];
$classfile = $classname.'.class';
$classcode = '<?php class '.$classname.' {' ."\n";
foreach(static::$class['attr'] as $name=>$value) {
$classcode.= 'public $'.$name.'='.'"'.$value.'"'.';'."\n";
}
$classcode.= '}';
file_put_contents($classfile,$classcode);
require_once($classfile);
static::$state = '';
}
public static function python_def($a) {
static::$def = array(
'name' => $a->name,
);
}
public static function python_def_end() {
$funcname = static::$def['name'];
eval('function '.$funcname.'(){}');
}
public static function python_comparsion($a,$op,$b) {
echo 'comp:';
static::python_test_name($a);
static::python_test_name($b);
var_dump($a,$op,$b);
die();
}
public static function python_test_name($a) {
if (is_object($a)) {
if (!isset(static::$names[$a->name])) {
throw new Exception('NameError');
}
}
}
public static function python_statament_run($a) {
echo "RUN!\n";
static::$statament->run($a);
python_statament_set(null);
}
public static function python_statament_set($a) {
echo "SET!\n";
static::$statament = $a;
}
public static function python_import($n) {
//echo 'import:';
//var_dump($n);
$file = $n->name.".py";
lang_python::python_execfile($file,false);
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.