@@ -87,16 +87,24 @@ int SimpleString(char *command, double* result) {
87
87
return ZF_SUCCESS ; // set the exit status code
88
88
}
89
89
90
- int SimpleStringN (char * command , char * resultVar , double * result ) {
90
+ int SimpleStringN (char * command , char * resultVar , char * result ) {
91
91
PyRun_SimpleString (command );
92
92
93
93
PyObject * mainModule = PyImport_AddModule ("__main__" );
94
94
95
95
//char varName = *resultVar;
96
96
97
97
PyObject * var = PyObject_GetAttrString (mainModule , resultVar );
98
- * result = PyFloat_AsDouble (var );
98
+ //*result = PyFloat_AsDouble(var);
99
+
100
+ //PyObject* objectsRepresentation = PyObject_Repr(var);
101
+ PyObject * objectsRepresentation = PyObject_Str (var );
102
+ char * s = PyUnicode_AsUTF8 (objectsRepresentation );
103
+
104
+ sprintf (result ,"%s" ,s );
99
105
106
+ //strcpy (result, s);
107
+ //result = s;
100
108
// TODO
101
109
// https://stackoverflow.com/questions/5356773/python-get-string-representation-of-pyobject
102
110
@@ -106,12 +114,20 @@ int SimpleStringN(char *command, char *resultVar, double* result) {
106
114
}
107
115
108
116
int main (int argc , char * * argv ) {
109
- printf ("Random : " );
117
+ printf ("X : " );
110
118
//exec_interactive_interpreter(argc, argv);
111
- double random = 0 ;
119
+ // double random = 0;
112
120
//GetRandom(&random);
113
- GetRandomSimple (& random );
114
- printf ("%lf" , random );
121
+ //GetRandomSimple(&random);
122
+ // printf("%lf", random);
123
+ char * result = malloc (sizeof (char ) * 1024 );
124
+
125
+
126
+ Initialize ();
127
+ SimpleStringN ("x=2" , "x" , result );
128
+ Finalize ();
129
+
130
+ printf (result );
115
131
return 0 ;
116
132
}
117
133
@@ -120,5 +136,5 @@ ZFENTRY("Initialize","",Initialize)
120
136
ZFENTRY ("Finalize" ,"" ,Finalize )
121
137
ZFENTRY ("GetRandom" ,"D" ,GetRandom )
122
138
ZFENTRY ("SimpleString" ,"cD" ,SimpleString )
123
- ZFENTRY ("SimpleStringN" ,"ccD " ,SimpleStringN )
139
+ ZFENTRY ("SimpleStringN" ,"ccC " ,SimpleStringN )
124
140
ZFEND
0 commit comments