Author: juhliarik Date: Wed Oct 31 15:34:34 2007 New Revision: 41691 URL: http://svn.opensuse.org/viewcvs/yast?rev=41691&view=rev Log: added arguments for calling functions from python in YCP via eval (e.g.Sequencer) Modified: trunk/python-bindings/src/YCPDeclarations.h trunk/python-bindings/src/YCPTypes/Code.cc trunk/python-bindings/src/YPython.cc trunk/python-bindings/src/YPythonNamespace.cc Modified: trunk/python-bindings/src/YCPDeclarations.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPDeclaratio... ============================================================================== --- trunk/python-bindings/src/YCPDeclarations.h (original) +++ trunk/python-bindings/src/YCPDeclarations.h Wed Oct 31 15:34:34 2007 @@ -48,7 +48,6 @@ */ std::vector<cache_function_t *> _cache; - /** * Private construct. * Call YCPDeclarations::instance() to get pointer to YCPDeclarations @@ -56,7 +55,6 @@ */ YCPDeclarations(); - /** * Return item from function map which has key key. * Return borrowed reference! @@ -88,7 +86,7 @@ const cache_function_t *_getCachedFunction(PyFunctionObject *func) const; public: - ~YCPDeclarations(); + ~YCPDeclarations(); /** * Return number of parameters in declaration or -1 if function is not registered. Modified: trunk/python-bindings/src/YCPTypes/Code.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPTypes/Code... ============================================================================== --- trunk/python-bindings/src/YCPTypes/Code.cc (original) +++ trunk/python-bindings/src/YCPTypes/Code.cc Wed Oct 31 15:34:34 2007 @@ -21,12 +21,14 @@ self = (Code *)type->tp_alloc(type, 0); if (self != NULL){ - self->value = Py_None; + + self->value = PyTuple_New(0); if (self->value == NULL){ Py_XDECREF(self); return NULL; } + self->hash = -1; } @@ -51,35 +53,38 @@ return -1; } - // value: + // check if first argument is function + tmp = PyTuple_GetItem(args, 0); + if (!PyFunction_Check(tmp)) { + PyErr_SetString(PyExc_TypeError, ": argument 1 must be function"); + return -1; + } + // value + value = PyTuple_GetSlice(args, 0, args_size); //args; + if (value != NULL) { + tmp = self->value; + self->value = value; + Py_XDECREF(tmp); + } + + + + + + /* value = PyTuple_GetItem(args, 0); if (PyFunction_Check(value)){ tmp = PyFunction_GetCode(self->value); Py_INCREF(value); self->value = value; - /* - printf("Code_init...\n"); - pReturn = PyObject_CallObject(self->value, NULL); - if (pReturn != NULL) - printf("Calling value: %d",PyInt_AsLong(pReturn)); - else - printf("pReturn == NULL");*/ Py_XDECREF(tmp); } else { PyErr_SetString(PyExc_TypeError, ": argument 1 must be function"); return -1; } - /* - // value: - if (args_size > 1){ - value = PyTuple_GetSlice(args, 1, args_size); // return new reference - if (value != NULL){ - tmp = self->value; - self->value = value; - Py_XDECREF(tmp); - } - } + */ + return 0; } Modified: trunk/python-bindings/src/YPython.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?re... ============================================================================== --- trunk/python-bindings/src/YPython.cc (original) +++ trunk/python-bindings/src/YPython.cc Wed Oct 31 15:34:34 2007 @@ -142,7 +142,7 @@ //create python string for name of module pModuleName = PyString_FromString(module_name.c_str()); //check if dictionary contain "dictionary" for module - if ( PyDict_Contains(YPython::_pMainDicts, pModuleName) == 0) { + if (PyDict_Contains(YPython::_pMainDicts, pModuleName) == 0) { pMain = PyImport_ImportModule(module_name.c_str()); if (pMain == NULL){ y2error("Can't import module %s", module_name.c_str()); @@ -689,9 +689,20 @@ PyObject * pReturn; YCPValue result = YCPVoid(); - + PyObject * pFunction; + PyObject * pArgs = NULL; + int args_size; + + args_size = PyTuple_Size(_pFunc); + + if (args_size >=1) { + pFunction = PyTuple_GetItem(_pFunc, 0); + if (args_size > 1) { + pArgs = PyTuple_GetSlice(_pFunc, 1, args_size); + } + } if (Py_IsInitialized()) { - pReturn = PyObject_CallObject(_pFunc, NULL); + pReturn = PyObject_CallObject(pFunction, pArgs); //convert python value to YCPValue if (pReturn) { result = YPython::yPython()->PythonTypeToYCPType(pReturn); // create YCP value Modified: trunk/python-bindings/src/YPythonNamespace.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPythonNamesp... ============================================================================== --- trunk/python-bindings/src/YPythonNamespace.cc (original) +++ trunk/python-bindings/src/YPythonNamespace.cc Wed Oct 31 15:34:34 2007 @@ -155,6 +155,7 @@ //Declarations (using YPCDelcarations python module) YCPDeclarations *decl = YCPDeclarations::instance(); + //YCPDeclarations *decl = new YCPDeclarations(); FunctionTypePtr sym_tp; std::vector<constTypePtr> list_of_types; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org