Skip to content

Commit e1808a7

Browse files
committed
some fix
1 parent 3bc4483 commit e1808a7

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
my_print(1, '2', 3.0, True, [None, ('a', 'b')])
2+
3+
a = [i for i in range(5)]
4+
my_print(*a, sep=' | ')
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "pocketpy.h"
2+
#include <stdio.h>
3+
4+
#define INPUT ""
5+
6+
static bool my_print(int argc, py_Ref argv) {
7+
PY_CHECK_ARGC(2);
8+
PY_CHECK_ARG_TYPE(0, tp_tuple);
9+
PY_CHECK_ARG_TYPE(1, tp_str);
10+
11+
int length = py_tuple_len(py_arg(0));
12+
const char *sep = py_tostr(py_arg(1));
13+
14+
for (int i = 0; i < length; i++) {
15+
py_Ref item = py_tuple_getitem(py_arg(0), i);
16+
if (!py_str(item)) {
17+
return false;
18+
}
19+
printf("%s", py_tostr(py_retval()));
20+
if (i < length - 1)
21+
printf("%s", sep);
22+
}
23+
printf("\n");
24+
py_newnone(py_retval());
25+
return true;
26+
}
27+
28+
int main() {
29+
py_initialize();
30+
31+
py_GlobalRef __main__ = py_getmodule("__main__");
32+
py_bind(__main__, "my_print(*args, sep=', ')", my_print);
33+
34+
if (!py_exec(INPUT, "main.py", EXEC_MODE, NULL)) {
35+
py_printexc();
36+
}
37+
38+
py_finalize();
39+
return 0;
40+
}

0 commit comments

Comments
 (0)