00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of rcssserver3D 00004 Fri May 9 2003 00005 Copyright (C) 2002,2003 Koblenz University 00006 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group 00007 $Id: rubywrapper.cpp,v 1.2 2004/02/20 12:22:24 rollmark Exp $ 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 */ 00022 #include "rubywrapper.h" 00023 00024 VALUE zeitgeist::RbFuncallWrap(VALUE arg) 00025 { 00026 RbArguments &a = *reinterpret_cast<RbArguments*>(arg); 00027 return rb_funcall2(a.recv, a.id, a.n, a.argv); 00028 } 00029 00030 VALUE zeitgeist::RbEvalStringWrap(const std::string& str, int& error) 00031 { 00032 VALUE v = rb_eval_string_protect(str.c_str(),&error); 00033 00034 if (error) 00035 { 00036 RbPrintError(); 00037 return Qnil; 00038 } 00039 00040 return v; 00041 } 00042 00043 00044 VALUE zeitgeist::RbEvalStringWrap(const std::string& str) 00045 { 00046 int error; 00047 return RbEvalStringWrap(str,error); 00048 } 00049 00050 std::string zeitgeist::RbGetError() 00051 { 00052 VALUE mes = rb_inspect(rb_gv_get("$!")); 00053 return RSTRING(mes)->ptr; 00054 } 00055 00056 void zeitgeist::RbPrintError() 00057 { 00058 std::cout << RbGetError() << std::endl; 00059 rb_backtrace(); 00060 } 00061 00062 00063