python: ucs2 and ucs4
parent
bd8d0b5d84
commit
175a469e49
|
@ -8,6 +8,7 @@ USING:
|
||||||
grouping
|
grouping
|
||||||
hashtables
|
hashtables
|
||||||
kernel
|
kernel
|
||||||
|
memoize
|
||||||
namespaces
|
namespaces
|
||||||
python.ffi
|
python.ffi
|
||||||
sequences
|
sequences
|
||||||
|
@ -50,7 +51,7 @@ ERROR: python-error type message ;
|
||||||
: with-py ( quot -- )
|
: with-py ( quot -- )
|
||||||
'[ Py_Initialize _ call Py_Finalize ] with-destructors ; inline
|
'[ Py_Initialize _ call Py_Finalize ] with-destructors ; inline
|
||||||
|
|
||||||
! Types and their methods
|
! Types
|
||||||
: <py-tuple> ( length -- tuple )
|
: <py-tuple> ( length -- tuple )
|
||||||
PyTuple_New check-return ;
|
PyTuple_New check-return ;
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ ERROR: python-error type message ;
|
||||||
: py-tuple-size ( obj -- len )
|
: py-tuple-size ( obj -- len )
|
||||||
PyTuple_Size ;
|
PyTuple_Size ;
|
||||||
|
|
||||||
|
! Dicts
|
||||||
: <py-dict> ( -- dict )
|
: <py-dict> ( -- dict )
|
||||||
PyDict_New check-return ;
|
PyDict_New check-return ;
|
||||||
|
|
||||||
|
@ -78,12 +80,21 @@ ERROR: python-error type message ;
|
||||||
: py-dict-size ( obj -- len )
|
: py-dict-size ( obj -- len )
|
||||||
PyDict_Size ;
|
PyDict_Size ;
|
||||||
|
|
||||||
|
! Lists
|
||||||
: py-list-size ( list -- len )
|
: py-list-size ( list -- len )
|
||||||
PyList_Size ;
|
PyList_Size ;
|
||||||
|
|
||||||
: py-list-get-item ( obj pos -- val )
|
: py-list-get-item ( obj pos -- val )
|
||||||
PyList_GetItem check-return ;
|
PyList_GetItem check-return ;
|
||||||
|
|
||||||
|
! Unicodes
|
||||||
|
: py-unicode>utf8 ( uni -- str )
|
||||||
|
PyUnicodeUCS2_AsUTF8String (check-return)
|
||||||
|
PyString_AsString (check-return)
|
||||||
|
|
||||||
|
MEMO: py-ucs-size ( -- n )
|
||||||
|
"maxunicode" PySys_GetObject check-return PyInt_AsLong 0xffff = 2 4 ? ;
|
||||||
|
|
||||||
! Data marshalling to Python
|
! Data marshalling to Python
|
||||||
GENERIC: (>py) ( obj -- obj' )
|
GENERIC: (>py) ( obj -- obj' )
|
||||||
M: string (>py) PyUnicodeUCS2_FromString ;
|
M: string (>py) PyUnicodeUCS2_FromString ;
|
||||||
|
|
Loading…
Reference in New Issue