]> gitweb.factorcode.org Git - factor.git/commitdiff
python: setattr wrapping
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 30 Jan 2014 14:06:30 +0000 (15:06 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 4 Mar 2014 17:23:04 +0000 (09:23 -0800)
extra/python/ffi/ffi.factor
extra/python/python-tests.factor
extra/python/python.factor

index 0d51c55e54547b001406ae0c942f056181997f51..dc04558c00ba44b85a0bf79aef4fd58a107a203f 100644 (file)
@@ -72,8 +72,13 @@ FUNCTION: PyObject* PyObject_CallObject ( PyObject* callable,
 FUNCTION: PyObject* PyObject_Call ( PyObject* callable,
                                     PyObject* args,
                                     PyObject* kw ) ;
-FUNCTION: PyObject* PyObject_GetAttrString ( PyObject* callable,
+! New reference
+FUNCTION: PyObject* PyObject_GetAttrString ( PyObject* o,
                                              c-string attr_name ) ;
+FUNCTION: int PyObject_SetAttrString ( PyObject* o,
+                                       c-string attr_name,
+                                       PyObject *v ) ;
+
 FUNCTION: PyObject* PyObject_Str ( PyObject* o ) ;
 FUNCTION: int PyObject_IsTrue ( PyObject* o ) ;
 
index 4a24f6e4be4912287b430707bd1abc128adbbc59..d2cb6927dd64efe78c06bcaf06d985c16188a014 100644 (file)
@@ -20,6 +20,11 @@ py-initialize
     [ "kolobi" import ] [ [ type>> ] [ message>> ] bi 2array ] recover
 ] py-test
 
+! setattr
+[ 73 ] [
+    "sys" import "testit" [ 73 >py setattr ] [ getattr >factor ] 2bi
+] py-test
+
 ! Tuples
 [ 2 ] [ 2 <py-tuple> py-tuple-size ] py-test
 
index 1f83f833778545f1bc3fb55c023af18352aca7e3..e7e819e1ad8a9de6b153bfa16b1bd55cb1a7ea18 100644 (file)
@@ -37,6 +37,9 @@ ERROR: python-error type message ;
 : getattr ( obj str -- value )
     PyObject_GetAttrString check-return ;
 
+: setattr ( obj str value -- )
+    PyObject_SetAttrString check-return-code ;
+
 : call-object ( obj args -- value )
     PyObject_CallObject check-return ;