From d5c0e84fe2d7a729fa2527a01959792acae1c305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Thu, 30 Jan 2014 15:06:30 +0100 Subject: [PATCH] python: setattr wrapping --- extra/python/ffi/ffi.factor | 7 ++++++- extra/python/python-tests.factor | 5 +++++ extra/python/python.factor | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/extra/python/ffi/ffi.factor b/extra/python/ffi/ffi.factor index 0d51c55e54..dc04558c00 100644 --- a/extra/python/ffi/ffi.factor +++ b/extra/python/ffi/ffi.factor @@ -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 ) ; diff --git a/extra/python/python-tests.factor b/extra/python/python-tests.factor index 4a24f6e4be..d2cb6927dd 100644 --- a/extra/python/python-tests.factor +++ b/extra/python/python-tests.factor @@ -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-size ] py-test diff --git a/extra/python/python.factor b/extra/python/python.factor index 1f83f83377..e7e819e1ad 100644 --- a/extra/python/python.factor +++ b/extra/python/python.factor @@ -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 ;