Skip to content

Commit a53f694

Browse files
committed
Test code for user objects.
1 parent d57eba5 commit a53f694

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

unix/main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,38 @@ void do_file(const char *file) {
131131
}
132132
}
133133

134+
void test_print(py_obj_t o_in) {
135+
printf("<test>");
136+
}
137+
138+
py_obj_t test_get(py_obj_t o_in) {
139+
py_obj_t d1;
140+
py_obj_t d2;
141+
py_user_get_data(o_in, &d1, &d2);
142+
return d1;
143+
}
144+
145+
py_obj_t test_set(py_obj_t o_in, py_obj_t arg) {
146+
py_user_set_data(o_in, (machine_uint_t)arg, (machine_uint_t)arg);
147+
return py_const_none;
148+
}
149+
150+
const py_user_info_t test_obj_info = {
151+
"Test",
152+
test_print,
153+
{
154+
{ "get", 0, test_get },
155+
{ "set", 1, test_set },
156+
{ NULL, 0, NULL },
157+
}
158+
};
159+
134160
int main(int argc, char **argv) {
135161
qstr_init();
136162
rt_init();
137163

164+
rt_store_name(qstr_from_str_static("test"), py_obj_new_user(&test_obj_info, py_obj_new_int(42), 0));
165+
138166
if (argc == 1) {
139167
do_repl();
140168
} else if (argc == 2) {

0 commit comments

Comments
 (0)