mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python/turtle] Use an init method to reset the turtle
This commit is contained in:
@@ -5,6 +5,14 @@ extern "C" {
|
||||
|
||||
static Turtle sTurtle;
|
||||
|
||||
mp_obj_t modturtle___init__() {
|
||||
sTurtle = Turtle();
|
||||
/* Note: we don't even bother writing a destructor for Turtle because this
|
||||
* init function is called once, and only once, per MicroPython init cycle.
|
||||
* When the previous Turtle object is destroyed, its VM is long gone. */
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t modturtle_forward(mp_obj_t px) {
|
||||
sTurtle.forward(mp_obj_get_float(px));
|
||||
return mp_const_none;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <py/obj.h>
|
||||
|
||||
mp_obj_t modturtle___init__();
|
||||
|
||||
mp_obj_t modturtle_forward(mp_obj_t px);
|
||||
mp_obj_t modturtle_backward(mp_obj_t px);
|
||||
mp_obj_t modturtle_right(mp_obj_t deg);
|
||||
|
||||
@@ -22,8 +22,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(modturtle_showturtle_obj, modturtle_showturtle)
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modturtle_hideturtle_obj, modturtle_hideturtle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modturtle_isvisible_obj, modturtle_isvisible);
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modturtle___init___obj, modturtle___init__);
|
||||
|
||||
STATIC const mp_rom_map_elem_t modturtle_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_turtle) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), (mp_obj_t)&modturtle___init___obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_forward), (mp_obj_t)&modturtle_forward_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_fd), (mp_obj_t)&modturtle_forward_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_backward), (mp_obj_t)&modturtle_backward_obj },
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
// add bunch of once-off options. May need refactoring later
|
||||
#define MICROPY_CPYTHON_COMPAT (0)
|
||||
|
||||
// modturtle needs a hook upon init
|
||||
#define MICROPY_MODULE_BUILTIN_INIT (1)
|
||||
|
||||
// Support for async/await/async for/async with
|
||||
#define MICROPY_PY_ASYNC_AWAIT (0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user