Exemple #1
0
bp::object PyHandle::GetAttribute( const char *name )
{
	if( hasattr(PyGet(), name) )
		return PyGet().attr("__getattribute__")(name);
	boost::python::object self = boost::python::object(
		boost::python::handle<>(
		boost::python::borrowed(GetPySelf())
		)
	);
	Assert( self.ptr() != NULL );
	return builtins.attr("object").attr("__getattribute__")(self, name);	
}
Exemple #2
0
void PyFunc::operator() (){

    bpy::object py_output;
    if(supply_input){

        // TODO: currently assuming pyfunc only operate on vectors.
        for(unsigned i = 0; i < input.size1(); ++i){
            py_input[i] = input(i, 0);
        }

        if(supply_time){
            py_output = py_fn(*time, py_input);
        }else{
            py_output = py_fn(py_input);
        }
    }else{
        if(supply_time){
            py_output = py_fn(*time);
        }else{
            py_output = py_fn();
        }
    }

    if(get_output){
        if(hasattr(py_output, "ndim")){
            // TODO: currently assuming pyfunc only operate on vectors.
            for(unsigned i = 0; i < output.size1(); ++i){
                output(i, 0) = bpy::extract<dtype>(py_output[i]);
            }
        }else{
            output(0, 0) = bpy::extract<dtype>(py_output);
        }
    }

    run_dbg(*this);
}
Exemple #3
0
}

static char setattribute_doc[] = "\
This function acts like object.__setattr__(), except that it\n\
does not cause a persistent instance's state to be loaded and it\n\
can be applied to instances of PersistentBase when the class is\n\
implemented in C.";

static char delattribute_doc[] = "\
This function acts like object.__delattr__(), except that it\n\
does not cause a persistent instance's state to be loaded and it\n\
can be applied to instances of PersistentBase when the class is\n\
implemented in C.";

static char hasattribute_doc[] = "\
This function acts like hasattr(), except that it does not cause\n\
a persistent instance's state to be loaded.";

static char getattribute_doc[] = "\
This function acts like object.__getattribute__().";

static char call_if_persistent_doc[] = "\
If the argument is a PersistentBase, call f on it.\n\
Otherwise, return None.";

static PyMethodDef persistent_module_methods[] = {
	{"_setattribute", setattribute, METH_VARARGS, setattribute_doc},
	{"_delattribute", delattribute, METH_VARARGS, delattribute_doc},
	{"_hasattribute", hasattribute, METH_VARARGS, hasattribute_doc},
	{"_getattribute", getattribute, METH_VARARGS, getattribute_doc},
	{"call_if_persistent", call_if_persistent,