mirror of
https://github.com/pocketpy/pocketpy
synced 2026-03-23 21:50:17 +00:00
Compare commits
No commits in common. "a43ac63a82302fc7d4c6c0e03b5ed10464b9621c" and "bb653bd38377e186513239d3d58c69e962c987ec" have entirely different histories.
a43ac63a82
...
bb653bd383
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
void pk__add_module_pkpy();
|
||||
void pk__add_module_conio();
|
||||
void pk__add_module_os();
|
||||
void pk__add_module_sys();
|
||||
void pk__add_module_math();
|
||||
|
||||
@ -52,7 +52,6 @@ class array2d(Generic[T]):
|
||||
def copy_(self, other: 'array2d[T] | list[T]') -> None: ...
|
||||
|
||||
def tolist(self) -> list[list[T]]: ...
|
||||
def render(self) -> str: ...
|
||||
|
||||
# algorithms
|
||||
def count(self, value: T) -> int:
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
def _kbhit() -> int: ...
|
||||
def _getch() -> int: ...
|
||||
@ -1,6 +1,5 @@
|
||||
{
|
||||
"stubPath": "include/typings",
|
||||
"reportMissingModuleSource": "none",
|
||||
"reportArgumentType": "none",
|
||||
"pythonVersion": "3.10"
|
||||
}
|
||||
|
||||
@ -205,8 +205,6 @@ void VM__ctor(VM* self) {
|
||||
|
||||
// add modules
|
||||
pk__add_module_pkpy();
|
||||
pk__add_module_conio();
|
||||
|
||||
pk__add_module_os();
|
||||
pk__add_module_sys();
|
||||
pk__add_module_math();
|
||||
|
||||
@ -316,25 +316,6 @@ static bool array2d_tolist(int argc, py_Ref argv) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool array2d_render(int argc, py_Ref argv){
|
||||
PY_CHECK_ARGC(1);
|
||||
c11_sbuf buf;
|
||||
c11_sbuf__ctor(&buf);
|
||||
c11_array2d* self = py_touserdata(argv);
|
||||
for(int j = 0; j < self->n_rows; j++) {
|
||||
for(int i = 0; i < self->n_cols; i++) {
|
||||
py_Ref item = py_array2d__get(self, i, j);
|
||||
if(!py_str(item)) return false;
|
||||
c11_sbuf__write_sv(&buf, py_tosv(py_retval()));
|
||||
}
|
||||
if(j < self->n_rows - 1){
|
||||
c11_sbuf__write_char(&buf, '\n');
|
||||
}
|
||||
}
|
||||
c11_sbuf__py_submit(&buf, py_retval());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool array2d_count(int argc, py_Ref argv) {
|
||||
// def count(self, value: T) -> int: ...
|
||||
PY_CHECK_ARGC(2);
|
||||
@ -605,7 +586,6 @@ void pk__add_module_array2d() {
|
||||
py_bindmethod(array2d, "copy_", array2d_copy_);
|
||||
|
||||
py_bindmethod(array2d, "tolist", array2d_tolist);
|
||||
py_bindmethod(array2d, "render", array2d_render);
|
||||
py_bindmethod(array2d, "count", array2d_count);
|
||||
py_bindmethod(array2d, "find_bounding_rect", array2d_find_bounding_rect);
|
||||
py_bindmethod(array2d, "count_neighbors", array2d_count_neighbors);
|
||||
|
||||
@ -43,24 +43,10 @@ static bool os_getcwd(int argc, py_Ref argv) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool os_system(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
PY_CHECK_ARG_TYPE(0, tp_str);
|
||||
#if PK_IS_DESKTOP_PLATFORM
|
||||
const char* cmd = py_tostr(py_arg(0));
|
||||
int code = system(cmd);
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
#else
|
||||
return py_exception(tp_OSError, "system() is not supported on this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void pk__add_module_os() {
|
||||
py_Ref mod = py_newmodule("os");
|
||||
py_bindfunc(mod, "chdir", os_chdir);
|
||||
py_bindfunc(mod, "getcwd", os_getcwd);
|
||||
py_bindfunc(mod, "system", os_system);
|
||||
}
|
||||
|
||||
void pk__add_module_sys() {
|
||||
|
||||
@ -1,32 +1,5 @@
|
||||
#include "pocketpy/pocketpy.h"
|
||||
|
||||
void pk__add_module_pkpy() { py_newmodule("pkpy"); }
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <conio.h>
|
||||
|
||||
static bool conio__kbhit(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(0);
|
||||
int ret = _kbhit();
|
||||
py_newint(py_retval(), ret);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool conio__getch(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(0);
|
||||
int ret = _getch();
|
||||
py_newint(py_retval(), ret);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void pk__add_module_conio() {
|
||||
py_Ref mod = py_newmodule("conio");
|
||||
|
||||
#ifdef _WIN32
|
||||
py_bindfunc(mod, "_kbhit", conio__kbhit);
|
||||
py_bindfunc(mod, "_getch", conio__getch);
|
||||
#endif
|
||||
void pk__add_module_pkpy() {
|
||||
py_newmodule("pkpy");
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user