Beispiel #1
0
PyObject* PyBuiltInInput::__call__(vector<PyObject*>* args) {
    PyObject* x;
    PyStr* y;
    string input;
    char buffer[256];
    ostringstream msg;

    if (args->size() != 1) {
         msg << "TypeError: expected 1 arguments, got " << args->size();
        throw new PyException(PYWRONGARGCOUNTEXCEPTION,msg.str());
    }
    
    x = (*args)[0];

    if (x->getType()->typeId() != PyStrType) {
        throw new PyException(PYILLEGALOPERATIONEXCEPTION, "Invalid argument to input(): Expected str, found " + x->getType()->toString());
    }

    y = (PyStr*) x;

    cout << y->toString();

    ostringstream s;

    cin.getline(buffer, 256);
    
    while (cin.gcount() == 255) {
        s << buffer;
        cin.getline(buffer, 256);
    }
    
    s << buffer;

    return new PyStr(s.str());
}
Beispiel #2
0
PyObject* PyBuiltInFPrint::__call__(vector<PyObject*>* args) {
    //cerr << "In print() with " << args->size() << " args to print." <<  endl;
    string output = "";
    PyObject* x;
    PyObject* w;
    vector<PyObject*>* strargs = new vector<PyObject*>();
    ostringstream msg;

    if (args->size() != 1) {
        msg << "TypeError: expected 1 arguments, got " << args->size();
        throw new PyException(PYWRONGARGCOUNTEXCEPTION,msg.str());    }

    PyObject* arg = (*args)[0];
    output = arg->toString();

    if (arg->getType()->typeId()==PyStrType)
        output = processit(output);
    
    cout << output;

    return this;
}