lib
interpreter.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "interpreter.h"
00021 #include "script.h"
00022 #include "../main/manager.h"
00023 #include "../main/scriptcontainer.h"
00024
00025 #include <klibloader.h>
00026
00027 extern "C"
00028 {
00029 typedef int (*def_interpreter_func)(Kross::Api::InterpreterInfo*);
00030 }
00031
00032 using namespace Kross::Api;
00033
00034
00035
00036
00037
00038 InterpreterInfo::InterpreterInfo(const QString& interpretername, const QString& library, const QString& wildcard, QStringList mimetypes, Option::Map options)
00039 : m_interpretername(interpretername)
00040 , m_library(library)
00041 , m_wildcard(wildcard)
00042 , m_mimetypes(mimetypes)
00043 , m_options(options)
00044 , m_interpreter(0)
00045 {
00046 }
00047
00048 InterpreterInfo::~InterpreterInfo()
00049 {
00050 for(Option::Map::Iterator it = m_options.begin(); it != m_options.end(); ++it)
00051 delete it.data();
00052
00053 delete m_interpreter;
00054 m_interpreter = 0;
00055 }
00056
00057 const QString& InterpreterInfo::getInterpretername()
00058 {
00059 return m_interpretername;
00060 }
00061
00062 const QString& InterpreterInfo::getWildcard()
00063 {
00064 return m_wildcard;
00065 }
00066
00067 const QStringList InterpreterInfo::getMimeTypes()
00068 {
00069 return m_mimetypes;
00070 }
00071
00072 bool InterpreterInfo::hasOption(const QString& key)
00073 {
00074 return m_options.contains(key);
00075 }
00076
00077 InterpreterInfo::Option* InterpreterInfo::getOption(const QString name)
00078 {
00079 return m_options[name];
00080 }
00081
00082 const QVariant& InterpreterInfo::getOptionValue(const QString name, QVariant defaultvalue)
00083 {
00084 Option* o = m_options[name];
00085 return o ? o->value : defaultvalue;
00086 }
00087
00088 InterpreterInfo::Option::Map InterpreterInfo::getOptions()
00089 {
00090 return m_options;
00091 }
00092
00093 Interpreter* InterpreterInfo::getInterpreter()
00094 {
00095 if(m_interpreter)
00096 return m_interpreter;
00097
00098 kdDebug() << QString("Loading the interpreter library for %1").arg(m_interpretername) << endl;
00099
00100
00101 KLibLoader *libloader = KLibLoader::self();
00102
00103 KLibrary* library = libloader->globalLibrary( m_library.latin1() );
00104 if(! library) {
00105
00106
00107
00108
00109
00110 kdWarning() << QString("Could not load library \"%1\" for the \"%2\" interpreter.").arg(m_library).arg(m_interpretername) << endl;
00111 return 0;
00112 }
00113
00114
00115 def_interpreter_func interpreter_func;
00116 interpreter_func = (def_interpreter_func) library->symbol("krossinterpreter");
00117 if(! interpreter_func) {
00118
00119 kdWarning() << "Failed to load the 'krossinterpreter' symbol from the library." << endl;
00120 }
00121 else {
00122
00123 m_interpreter = (Interpreter*) (interpreter_func)(this);
00124 if(! m_interpreter) {
00125 kdWarning() << "Failed to load the Interpreter instance from library." << endl;
00126 }
00127 else {
00128
00129
00130 kdDebug()<<"Successfully loaded Interpreter instance from library."<<endl;
00131 }
00132 }
00133
00134
00135 library->unload();
00136
00137 return m_interpreter;
00138 }
00139
00140
00141
00142
00143
00144 Interpreter::Interpreter(InterpreterInfo* info)
00145 : m_interpreterinfo(info)
00146 {
00147 }
00148
00149 Interpreter::~Interpreter()
00150 {
00151 }
|