补充
This commit is contained in:
25
Test/CPythonTest/App/cpython.py
Normal file
25
Test/CPythonTest/App/cpython.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import t, c
|
||||
|
||||
|
||||
class PyObject:
|
||||
ob_refcnt: t.CLong
|
||||
ob_type: t.CPtr
|
||||
|
||||
|
||||
def Py_Initialize() -> t.CVoid | t.CExtern:
|
||||
pass
|
||||
|
||||
def PyLong_FromLong(value: t.CLong) -> PyObject | t.CPtr | t.CExtern:
|
||||
pass
|
||||
|
||||
def PyObject_Str(obj: PyObject | t.CPtr) -> PyObject | t.CPtr | t.CExtern:
|
||||
pass
|
||||
|
||||
def PyUnicode_AsUTF8(unicode_obj: PyObject | t.CPtr) -> str | t.CExtern:
|
||||
pass
|
||||
|
||||
def Py_DecRef(obj: PyObject | t.CPtr) -> t.CVoid | t.CExtern:
|
||||
pass
|
||||
|
||||
def Py_Finalize() -> t.CVoid | t.CExtern:
|
||||
pass
|
||||
28
Test/CPythonTest/App/main.py
Normal file
28
Test/CPythonTest/App/main.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import t, c
|
||||
from t import CInt, CPtr, CChar, CLong
|
||||
import viperlib
|
||||
import cpython
|
||||
|
||||
|
||||
def SetDllDirectoryA(lpPathName: str | CPtr) -> CInt | t.CExtern:
|
||||
pass
|
||||
|
||||
def main() -> CInt | t.CExport:
|
||||
SetDllDirectoryA("D:\\Python312")
|
||||
|
||||
cpython.Py_Initialize()
|
||||
|
||||
py_num: cpython.PyObject | t.CPtr = cpython.PyLong_FromLong(12345)
|
||||
|
||||
py_str: cpython.PyObject | t.CPtr = cpython.PyObject_Str(py_num)
|
||||
c_str: str = cpython.PyUnicode_AsUTF8(py_str)
|
||||
print(c_str)
|
||||
|
||||
cpython.Py_DecRef(py_str)
|
||||
cpython.Py_DecRef(py_num)
|
||||
|
||||
cpython.Py_Finalize()
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user