PDA

View Full Version : Simple Scripting language



shawk
30th July 2012, 23:31
I am trying to make a simple scripting laungange in qt that you can change variables from c++ in the script and the return it back so far this what I have:


QString Script = "def SH_Script Print hello hey; Print hey;";

if(Script.startsWith("def SH_Script", Qt::CaseInsensitive))
{
Script.replace(QRegExp("def SH_Script"), "");
QStringList Lines = Script.split(";");
QStringList Words[Lines.count()];

for(int i = 0; i < Lines.count(); i++)
{
Words[i] = Lines.at(i).split(" ");

for(int w = 0; w < Words[i].count(); w++)
{
if(Words[i].at(w) == "Print")
{
for(int h = 0; h < Words[i].count(); h++)
{
if(Words[i].at(h) == "Print")
{
Words[i].removeAt(h);
}
}

QString output;
for(int a = 1; a < Words[i].count(); a++)
{
output += Words[i].at(a) + " ";
}

qDebug() << output << endl;
output = "";
}

else if(Words[i].at(w) == "def")
{
//creates a new varible
}

else if(Words[i].at(w).startsWith('$'))
{
//refers to a varible
}

else if(Words[i].at(w).startsWith("--"))
{
Words[i].clear();
}
else if(Words[i].at(w) == " ")
{
//reconizing space instead of errors
}
else if(Words[i].at(w) == "")
{
//reconizing space instead of errors
}
else
{
qDebug() << "syntax error at line:" << i;
}
}
}
}
else
{
qDebug() << "Not decarled as a SH Script";
}



Any suggestions or help would be great

StrikeByte
31st July 2012, 10:08
have you seen this thread? http://www.qtcentre.org/threads/698-QSA-loading-scripts-at-runtime

i see that QSA is depricated the new sript is QtScript