mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
add win32
module
This commit is contained in:
parent
42bbf6fdb4
commit
2c7f0cdd07
@ -44,6 +44,11 @@ if(PK_ENABLE_OS)
|
|||||||
add_definitions(-DPK_ENABLE_OS=1)
|
add_definitions(-DPK_ENABLE_OS=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
option(PK_MODULE_WIN32 "" OFF)
|
||||||
|
if(PK_MODULE_WIN32)
|
||||||
|
add_definitions(-DPK_MODULE_WIN32=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
# PK_IS_MAIN determines whether the project is being used from root
|
# PK_IS_MAIN determines whether the project is being used from root
|
||||||
# or if it is added as a dependency (through add_subdirectory for example).
|
# or if it is added as a dependency (through add_subdirectory for example).
|
||||||
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
|
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
@ -73,3 +78,7 @@ if(UNIX)
|
|||||||
target_link_libraries(${PROJECT_NAME} m)
|
target_link_libraries(${PROJECT_NAME} m)
|
||||||
target_link_libraries(${PROJECT_NAME} dl)
|
target_link_libraries(${PROJECT_NAME} dl)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(PK_MODULE_WIN32)
|
||||||
|
target_link_libraries(${PROJECT_NAME} winmm.lib)
|
||||||
|
endif()
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void pk__add_module_pkpy();
|
|
||||||
void pk__add_module_conio();
|
|
||||||
void pk__add_module_os();
|
void pk__add_module_os();
|
||||||
void pk__add_module_sys();
|
void pk__add_module_sys();
|
||||||
void pk__add_module_math();
|
void pk__add_module_math();
|
||||||
@ -15,3 +13,5 @@ void pk__add_module_traceback();
|
|||||||
void pk__add_module_enum();
|
void pk__add_module_enum();
|
||||||
void pk__add_module_linalg();
|
void pk__add_module_linalg();
|
||||||
void pk__add_module_array2d();
|
void pk__add_module_array2d();
|
||||||
|
|
||||||
|
void pk__add_module_win32();
|
@ -1,2 +0,0 @@
|
|||||||
def _kbhit() -> int: ...
|
|
||||||
def _getch() -> int: ...
|
|
@ -1 +0,0 @@
|
|||||||
from typing import Any
|
|
4
include/typings/win32.pyi
Normal file
4
include/typings/win32.pyi
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
def _kbhit() -> int: ...
|
||||||
|
def _getch() -> int: ...
|
||||||
|
|
||||||
|
def PlaySoundA(pszSound: str, hmod: int, fdwSound: int) -> bool: ...
|
@ -204,9 +204,6 @@ void VM__ctor(VM* self) {
|
|||||||
pk__add_module_array2d();
|
pk__add_module_array2d();
|
||||||
|
|
||||||
// add modules
|
// add modules
|
||||||
pk__add_module_pkpy();
|
|
||||||
pk__add_module_conio();
|
|
||||||
|
|
||||||
pk__add_module_os();
|
pk__add_module_os();
|
||||||
pk__add_module_sys();
|
pk__add_module_sys();
|
||||||
pk__add_module_math();
|
pk__add_module_math();
|
||||||
@ -219,6 +216,9 @@ void VM__ctor(VM* self) {
|
|||||||
pk__add_module_traceback();
|
pk__add_module_traceback();
|
||||||
pk__add_module_enum();
|
pk__add_module_enum();
|
||||||
|
|
||||||
|
// add win32 module
|
||||||
|
pk__add_module_win32();
|
||||||
|
|
||||||
// add python builtins
|
// add python builtins
|
||||||
do {
|
do {
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
#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
|
|
||||||
}
|
|
47
src/modules/win32.c
Normal file
47
src/modules/win32.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include "pocketpy/pocketpy.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32) && defined(PK_MODULE_WIN32)
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <conio.h>
|
||||||
|
|
||||||
|
static bool win32__kbhit(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(0);
|
||||||
|
int ret = _kbhit();
|
||||||
|
py_newint(py_retval(), ret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool win32__getch(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(0);
|
||||||
|
int ret = _getch();
|
||||||
|
py_newint(py_retval(), ret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool win32_PlaySoundA(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(3);
|
||||||
|
PY_CHECK_ARG_TYPE(0, tp_str);
|
||||||
|
PY_CHECK_ARG_TYPE(1, tp_int);
|
||||||
|
PY_CHECK_ARG_TYPE(2, tp_int);
|
||||||
|
const char* pszSound = py_tostr(argv);
|
||||||
|
py_i64 hmod = py_toint(py_arg(1));
|
||||||
|
py_i64 fdwSound = py_toint(py_arg(2));
|
||||||
|
int ret = PlaySoundA(pszSound, (HMODULE)hmod, fdwSound);
|
||||||
|
py_newbool(py_retval(), ret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void pk__add_module_win32() {
|
||||||
|
#if defined(_WIN32) && defined(PK_MODULE_WIN32)
|
||||||
|
py_Ref mod = py_newmodule("win32");
|
||||||
|
|
||||||
|
py_bindfunc(mod, "_kbhit", win32__kbhit);
|
||||||
|
py_bindfunc(mod, "_getch", win32__getch);
|
||||||
|
|
||||||
|
py_bindfunc(mod, "PlaySoundA", win32_PlaySoundA);
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user