blueloveTH hai 9 meses
pai
achega
70e824a6b6
Modificáronse 3 ficheiros con 6 adicións e 4 borrados
  1. 1 1
      include/pocketpy/pocketpy.h
  2. 4 2
      src/interpreter/vm.c
  3. 1 1
      src/public/modules.c

+ 1 - 1
include/pocketpy/pocketpy.h

@@ -77,7 +77,7 @@ typedef struct py_Callbacks {
     /// Flush the output buffer of `print`.
     void (*flush)();
     /// Used by `input` to get a character.
-    int (*getchar)();
+    int (*getchr)();
     /// Used by `gc.collect()` to mark extra objects for garbage collection.
     void (*gc_mark)(void (*f)(py_Ref val, void* ctx), void* ctx);
 } py_Callbacks;

+ 4 - 2
src/interpreter/vm.c

@@ -32,6 +32,8 @@ static void pk_default_print(const char* data) { printf("%s", data); }
 
 static void pk_default_flush() { fflush(stdout); }
 
+static int pk_default_getchr() { return getchar(); }
+
 void LineProfiler__tracefunc(py_Frame* frame, enum py_TraceEvent event) {
     LineProfiler* self = &pk_current_vm->line_profiler;
     if(self->enabled && event == TRACE_EVENT_LINE) { LineProfiler__tracefunc_line(self, frame); }
@@ -75,7 +77,7 @@ void VM__ctor(VM* self) {
     self->callbacks.importfile = pk_default_importfile;
     self->callbacks.print = pk_default_print;
     self->callbacks.flush = pk_default_flush;
-    self->callbacks.getchar = getchar;
+    self->callbacks.getchr = pk_default_getchr;
 
     self->last_retval = *py_NIL();
     self->curr_exception = *py_NIL();
@@ -810,7 +812,7 @@ int py_replinput(char* buf, int max_size) {
     printf(">>> ");
 
     while(true) {
-        int c = pk_current_vm->callbacks.getchar();
+        int c = pk_current_vm->callbacks.getchr();
         if(c == EOF) return -1;
 
         if(c == '\n') {

+ 1 - 1
src/public/modules.c

@@ -205,7 +205,7 @@ static bool builtins_input(int argc, py_Ref argv) {
     c11_sbuf buf;
     c11_sbuf__ctor(&buf);
     while(true) {
-        int c = py_callbacks()->getchar();
+        int c = py_callbacks()->getchr();
         if(c == '\n' || c == '\r') break;
         if(c == EOF) break;
         c11_sbuf__write_char(&buf, c);