[ "os" ] [ "os" import PyModule_GetName ] py-test
-[ t ] [ "os" import "getpid" getattr { } py-call 0 > ] py-test
+[ t ] [
+ "os" import "getpid" getattr
+ { } >py call-object >factor 0 >
+] py-test
[ t ] [ Py_IsInitialized ] py-test
! ! Datetimes
[ t ] [
[ py-date>factor ] "date" py-type-dispatch get set-at
- "datetime" import
- "date" getattr "today" getattr
- { } py-call
+ "datetime" import "date" getattr "today" getattr
+ { } >py call-object >factor
today instant >>gmt-offset =
] py-test
! Unicode
[ "غثههح" ] [
- "os.path" import "basename" getattr { "غثههح" } py-call
+ "os.path" import "basename" getattr { "غثههح" } >py call-object >factor
] py-test
! Instance variables
! Kwargs
[ 2014 10 22 ] [
"datetime" import "date" getattr
- { } { "year" 2014 "month" 10 "day" 22 } py-call2
- [ year>> ] [ month>> ] [ day>> ] tri
-] py-test
-
-SYMBOLS: year month day ;
-
-[ 2014 10 22 ] [
- "datetime" import "date" getattr
- { } { year 2014 month 10 day 22 } py-call2
+ { } >py H{ { "year" 2014 } { "month" 10 } { "day" 22 } } >py
+ call-object-full >factor
[ year>> ] [ month>> ] [ day>> ] tri
] py-test
-USING: accessors alien alien.c-types alien.data arrays assocs fry grouping
-hashtables kernel namespaces python.ffi sequences strings vectors words ;
+USING: accessors alien alien.c-types alien.data arrays assocs fry
+hashtables kernel namespaces python.ffi sequences strings vectors ;
IN: python
QUALIFIED: math
: call-object ( obj args -- value )
PyObject_CallObject check-return ;
+: call-object-full ( obj args kwargs -- value )
+ PyObject_Call check-return ;
+
! Types
: <py-tuple> ( length -- tuple )
PyTuple_New check-return ;
M: vector (>py)
[ (>py) ] map vector>py-list ;
-M: word (>py) name>> (>py) ;
-
: >py ( obj -- py-obj )
(>py) &Py_DecRef ;
: >factor ( py-obj -- obj )
dup "__class__" getattr "__name__" getattr PyString_AsString
py-type-dispatch get ?at [ call( x -- x ) ] [ missing-type ] if ;
-
-! Utility
-: py-call ( obj args -- value )
- >py call-object >factor ;
-
-: py-call2 ( obj args kwargs -- value )
- [ >py ] [ 2 group >hashtable >py ] bi* PyObject_Call >factor ;
py-initialize
+<PRIVATE
+
SYMBOL: current-context
: with-each-definition ( quot -- )
[ dup current-context get import swap getattr 2dup ] dip
function-callable function-object ; inline
-SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline
-
: make-method-quot ( name in out -- ret )
swapd '[
_ narray array>py-tuple swap
[ [ in>> length 1 - ] [ out>> length ] bi make-method-quot ] keep
define-inline method-object ;
+PRIVATE>
+
+SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline
+
SYNTAX: PY-METHODS: [ add-method ] scan-definitions ; inline