mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-11 16:22:12 +00:00
Fix dumdum issue with singles ARGs - again...
This commit is contained in:
parent
68c5ef214f
commit
444fc24e1d
@ -5,7 +5,7 @@
|
|||||||
//bool DEVELOPER_MESSAGES = true;
|
//bool DEVELOPER_MESSAGES = true;
|
||||||
#define DEVELOPER_MESSAGES false
|
#define DEVELOPER_MESSAGES false
|
||||||
#define EXAMPLE_PROJECT false
|
#define EXAMPLE_PROJECT false
|
||||||
#define NAMEVERSION "ZSharp v2.1.1-alpha"
|
#define NAMEVERSION "ZSharp v2.1.2-alpha"
|
||||||
|
|
||||||
#if defined(__unix__)
|
#if defined(__unix__)
|
||||||
#define UNIX true
|
#define UNIX true
|
||||||
@ -78,12 +78,12 @@ boost::any GetVariableValue(const string& varName, const unordered_map<string, b
|
|||||||
// Check if there is a variable with the specified name
|
// Check if there is a variable with the specified name
|
||||||
bool IsVar(const string& varName, const unordered_map<string, boost::any>& variableValues)
|
bool IsVar(const string& varName, const unordered_map<string, boost::any>& variableValues)
|
||||||
{
|
{
|
||||||
if(split(varName, '.')[0] == "ZS")
|
if (split(varName, '.')[0] == "ZS")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (variableValues.find(split(varName, '.')[0]) != variableValues.end())
|
if (variableValues.find(split(varName, '.')[0]) != variableValues.end())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
string insideFunArgs = betweenChars(expression, '(', ')');
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
cout << "[" << unWrapVec(argList) << "]" << endl;
|
cout << split(expression, '(')[0] << " [" << unWrapVec(argList) << "]" << endl;
|
||||||
printVarValues(argList, variableValues);
|
printVarValues(argList, variableValues);
|
||||||
#endif
|
#endif
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
||||||
@ -176,7 +176,7 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
string insideFunArgs = betweenChars(expression, '(', ')');
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
cout << split(expression, '(')[0]<< " [" << unWrapVec(argList) << "]" << endl;
|
cout << split(expression, '(')[0] << " [" << unWrapVec(argList) << "]" << endl;
|
||||||
printVarValues(argList, variableValues);
|
printVarValues(argList, variableValues);
|
||||||
#endif
|
#endif
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
||||||
@ -288,9 +288,9 @@ bool BooleanLogic(const string& valA, const string& comparer, const string& valB
|
|||||||
{
|
{
|
||||||
boost::any valARealValue;
|
boost::any valARealValue;
|
||||||
boost::any valBRealValue;
|
boost::any valBRealValue;
|
||||||
if(valA != "")
|
if (valA != "")
|
||||||
valARealValue = EvalExpression(valA, variableValues);
|
valARealValue = EvalExpression(valA, variableValues);
|
||||||
if(valB != "")
|
if (valB != "")
|
||||||
valBRealValue = EvalExpression(valB, variableValues);
|
valBRealValue = EvalExpression(valB, variableValues);
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog(AnyAsString(valARealValue) + " " + comparer + " " + AnyAsString(valBRealValue) + " : " + AnyAsString(valA) + " " + comparer + " " + AnyAsString(valB) + " : " + to_string(AnyAsString(valARealValue) == AnyAsString(valBRealValue)));
|
InterpreterLog(AnyAsString(valARealValue) + " " + comparer + " " + AnyAsString(valBRealValue) + " : " + AnyAsString(valA) + " " + comparer + " " + AnyAsString(valB) + " : " + to_string(AnyAsString(valARealValue) == AnyAsString(valBRealValue)));
|
||||||
@ -419,22 +419,16 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
// Check if it is function call
|
// Check if it is function call
|
||||||
else if (IsFunction(split(words.at(lineNum).at(0), '(')[0]))
|
else if (IsFunction(split(words.at(lineNum).at(0), '(')[0]))
|
||||||
{
|
{
|
||||||
// No args provided
|
// start -> FuncCall(0, x, OtherFunc(a))
|
||||||
if (indexInStr(words.at(lineNum).at(0), ')') - indexInStr(words.at(lineNum).at(0), '(')<=1)
|
// changeto -> 0, x, OtherFunc(a)
|
||||||
ExecuteFunction(split(words.at(lineNum).at(0), '(')[0], vector<boost::any>());
|
string insideFunArgs = betweenChars(unWrapVec(words.at(lineNum)), '(', ')');
|
||||||
else
|
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
||||||
{ // Args provided, parse them first
|
|
||||||
// start -> FuncCall(0, x, OtherFunc(a))
|
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
|
||||||
string insideFunArgs = betweenChars(unWrapVec(words.at(lineNum)), '(', ')');
|
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
cout << unWrapVec(argList) << endl;
|
cout << unWrapVec(argList) << endl;
|
||||||
printVarValues(argList, variableValues);
|
printVarValues(argList, variableValues);
|
||||||
#endif
|
#endif
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
||||||
ExecuteFunction(split(words.at(lineNum).at(0), '(')[0], funcArgs);
|
ExecuteFunction(split(words.at(lineNum).at(0), '(')[0], funcArgs);
|
||||||
}
|
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,9 +514,9 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the statement is already false, don't bother gathering the contents
|
// If the statement is already false, don't bother gathering the contents
|
||||||
if(BooleanLogic(whileParameters.at(0), whileParameters.at(1), whileParameters.at(2), variableValues) == false){
|
if (BooleanLogic(whileParameters.at(0), whileParameters.at(1), whileParameters.at(2), variableValues) == false) {
|
||||||
lineNum++;
|
lineNum++;
|
||||||
while (lineNum < (int)words.size())
|
while (lineNum < (int)words.size())
|
||||||
{
|
{
|
||||||
@ -553,9 +547,9 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
//Iterate through all lines in while loop
|
//Iterate through all lines in while loop
|
||||||
for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++)
|
for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++)
|
||||||
{
|
{
|
||||||
if(whileContents.at(lineNum).at(0)== "continue")
|
if (whileContents.at(lineNum).at(0) == "continue")
|
||||||
break; // Stops iterating through lines and return to beginning
|
break; // Stops iterating through lines and return to beginning
|
||||||
if(whileContents.at(lineNum).at(0)== "break")
|
if (whileContents.at(lineNum).at(0) == "break")
|
||||||
return nullType; // Stops iterating through lines and leave while loop
|
return nullType; // Stops iterating through lines and leave while loop
|
||||||
boost::any returnVal = ProcessLine(whileContents, lineNum, variableValues);
|
boost::any returnVal = ProcessLine(whileContents, lineNum, variableValues);
|
||||||
if (!returnVal.empty()) {
|
if (!returnVal.empty()) {
|
||||||
@ -594,7 +588,7 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the statement is already false, don't bother gathering the contents
|
// If the statement is already false, don't bother gathering the contents
|
||||||
if(BooleanLogic(ifParameters.at(0), ifParameters.at(1), ifParameters.at(2), variableValues) == false){
|
if (BooleanLogic(ifParameters.at(0), ifParameters.at(1), ifParameters.at(2), variableValues) == false) {
|
||||||
lineNum++;
|
lineNum++;
|
||||||
while (lineNum < (int)words.size())
|
while (lineNum < (int)words.size())
|
||||||
{
|
{
|
||||||
@ -605,7 +599,7 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
}
|
}
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gather the contents
|
// Gather the contents
|
||||||
lineNum++;
|
lineNum++;
|
||||||
while (lineNum < (int)words.size())
|
while (lineNum < (int)words.size())
|
||||||
@ -624,7 +618,7 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
//Iterate through all lines in if statement
|
//Iterate through all lines in if statement
|
||||||
for (int l = 0; l < (int)ifContents.size(); l++)
|
for (int l = 0; l < (int)ifContents.size(); l++)
|
||||||
{
|
{
|
||||||
if(ifContents.at(l).at(0)== "break")
|
if (ifContents.at(l).at(0) == "break")
|
||||||
return breakReOp; // Stops iterating through lines and leave while loop
|
return breakReOp; // Stops iterating through lines and leave while loop
|
||||||
boost::any returnVal = ProcessLine(ifContents, l, variableValues);
|
boost::any returnVal = ProcessLine(ifContents, l, variableValues);
|
||||||
if (!returnVal.empty())
|
if (!returnVal.empty())
|
||||||
@ -718,8 +712,8 @@ int parseZSharp(string script)
|
|||||||
// Split the script by newline, signifying a line ending
|
// Split the script by newline, signifying a line ending
|
||||||
vector<string> beforeProcessLines = split(script, '\n');
|
vector<string> beforeProcessLines = split(script, '\n');
|
||||||
vector<string> lines;
|
vector<string> lines;
|
||||||
for (int i = 0; i < (int)beforeProcessLines.size(); i++){ // Then split said lines into indiviual words
|
for (int i = 0; i < (int)beforeProcessLines.size(); i++) { // Then split said lines into indiviual words
|
||||||
if(!startsWith(trim(beforeProcessLines.at(i)), "//") && trim(beforeProcessLines.at(i)) != "")
|
if (!startsWith(trim(beforeProcessLines.at(i)), "//") && trim(beforeProcessLines.at(i)) != "")
|
||||||
{ // dont include line if it is a comment or if it is blank
|
{ // dont include line if it is a comment or if it is blank
|
||||||
lines.push_back(trim(beforeProcessLines.at(i)));
|
lines.push_back(trim(beforeProcessLines.at(i)));
|
||||||
}
|
}
|
||||||
@ -836,7 +830,7 @@ int parseZSharp(string script)
|
|||||||
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through all types to see if line inits or
|
// Iterate through all types to see if line inits or
|
||||||
// re-inits a variable then store it with it's value
|
// re-inits a variable then store it with it's value
|
||||||
else if (countInVector(types, trim(words.at(lineNum).at(0))) > 0)
|
else if (countInVector(types, trim(words.at(lineNum).at(0))) > 0)
|
||||||
@ -844,24 +838,24 @@ int parseZSharp(string script)
|
|||||||
//cout << words.at(lineNum).at(1) << "=" << unWrapVec(slice(words.at(lineNum), 3, -1)) << "=" << AnyAsString(EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), variableValues)) << endl;
|
//cout << words.at(lineNum).at(1) << "=" << unWrapVec(slice(words.at(lineNum), 3, -1)) << "=" << AnyAsString(EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), variableValues)) << endl;
|
||||||
globalVariableValues[words.at(lineNum).at(1)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), globalVariableValues);
|
globalVariableValues[words.at(lineNum).at(1)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), globalVariableValues);
|
||||||
}
|
}
|
||||||
// else if (words.at(lineNum).at(0) == "int") {
|
// else if (words.at(lineNum).at(0) == "int") {
|
||||||
// globalVariableValues[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
|
// globalVariableValues[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
|
||||||
//#if DEVELOPER_MESSAGES == true
|
//#if DEVELOPER_MESSAGES == true
|
||||||
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
//#endif
|
//#endif
|
||||||
// }
|
// }
|
||||||
// else if (words.at(lineNum).at(0) == "float") {
|
// else if (words.at(lineNum).at(0) == "float") {
|
||||||
// globalVariableValues[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
|
// globalVariableValues[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
|
||||||
//#if DEVELOPER_MESSAGES == true
|
//#if DEVELOPER_MESSAGES == true
|
||||||
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
//#endif
|
//#endif
|
||||||
// }
|
// }
|
||||||
// else if (words.at(lineNum).at(0) == "bool") {
|
// else if (words.at(lineNum).at(0) == "bool") {
|
||||||
// globalVariableValues[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
|
// globalVariableValues[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
|
||||||
//#if DEVELOPER_MESSAGES == true
|
//#if DEVELOPER_MESSAGES == true
|
||||||
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
//#endif
|
//#endif
|
||||||
// }
|
// }
|
||||||
else
|
else
|
||||||
LogWarning("unrecognized type \'" + words.at(lineNum).at(0) + "\' on line: " + to_string(lineNum));
|
LogWarning("unrecognized type \'" + words.at(lineNum).at(0) + "\' on line: " + to_string(lineNum));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -409,8 +409,11 @@ boost::any ZSFunction(const string& name, const vector<boost::any>& args)
|
|||||||
}
|
}
|
||||||
else if (name == "ZS.Graphics.Sprite")
|
else if (name == "ZS.Graphics.Sprite")
|
||||||
{
|
{
|
||||||
if (!fileExists(StringRaw(AnyAsString(args.at(0)))))
|
string path = StringRaw(AnyAsString(args.at(0)));
|
||||||
LogCriticalError("Failed to create 'Sprite' object: \"" + StringRaw(AnyAsString(args.at(0))) + "\"");
|
if (count(path, '/') == 0)
|
||||||
|
path = "./" + path;
|
||||||
|
if (!fileExists(path))
|
||||||
|
LogCriticalError("Failed to create 'Sprite' object: \"" + path + "\"");
|
||||||
|
|
||||||
Sprite s(StringRaw(AnyAsString(args.at(0))), any_cast<Vec2>(args.at(1)), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)));
|
Sprite s(StringRaw(AnyAsString(args.at(0))), any_cast<Vec2>(args.at(1)), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)));
|
||||||
return s;
|
return s;
|
||||||
@ -421,17 +424,20 @@ boost::any ZSFunction(const string& name, const vector<boost::any>& args)
|
|||||||
any_cast<Sprite>(args.at(0)).Load();
|
any_cast<Sprite>(args.at(0)).Load();
|
||||||
else if (name == "ZS.Graphics.Text")
|
else if (name == "ZS.Graphics.Text")
|
||||||
{
|
{
|
||||||
if (!fileExists(StringRaw(AnyAsString(args.at(1)))))
|
string path = StringRaw(AnyAsString(args.at(1)));
|
||||||
LogCriticalError("Failed to create 'Text' object: \"" + StringRaw(AnyAsString(args.at(1))) + "\"");
|
if (count(path, '/') == 0)
|
||||||
|
path = "./" + path;
|
||||||
|
if (!fileExists(path))
|
||||||
|
LogCriticalError("Failed to create 'Text' object: \"" + path + "\"");
|
||||||
|
|
||||||
if (args.size() <= 8)
|
if (args.size() <= 8)
|
||||||
{
|
{
|
||||||
Text t(StringRaw(AnyAsString(args.at(0))), StringRaw(AnyAsString(args.at(1))), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)), true);
|
Text t(StringRaw(AnyAsString(args.at(0))), path, any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)), true);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Text t(StringRaw(AnyAsString(args.at(0))), StringRaw(AnyAsString(args.at(1))), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)), AnyAsBool(args.at(8)));
|
Text t(StringRaw(AnyAsString(args.at(0))), path, any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)), AnyAsBool(args.at(8)));
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1028,6 +1028,11 @@ int updateLoop()
|
|||||||
|
|
||||||
ExecuteFunction("Update", vector<boost::any> {dt});
|
ExecuteFunction("Update", vector<boost::any> {dt});
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(gRenderer, 255, 0, 0, 255);
|
||||||
|
for (int i = 0; i < WINDOW_WIDTH; ++i)
|
||||||
|
SDL_RenderDrawPoint(gRenderer, i, i);
|
||||||
|
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
||||||
|
|
||||||
// Present the backbuffer
|
// Present the backbuffer
|
||||||
SDL_RenderPresent(gRenderer);
|
SDL_RenderPresent(gRenderer);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user