mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
Almost done making linux version, window is showing but there is still an error
This commit is contained in:
parent
fa870f46d5
commit
ebc3954265
100
Slang/Main.cpp
100
Slang/Main.cpp
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#if UNIX
|
#if UNIX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <filesystem>
|
||||||
#elif WINDOWS
|
#elif WINDOWS
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
@ -541,26 +542,23 @@ boost::any ProcessLine(const vector<vector<string>>& words, int lineNum, unorder
|
|||||||
boost::any ExecuteFunction(const string& functionName, const vector<boost::any>& inputVarVals)
|
boost::any ExecuteFunction(const string& functionName, const vector<boost::any>& inputVarVals)
|
||||||
{
|
{
|
||||||
// Get contents of function
|
// Get contents of function
|
||||||
vector<vector<string>> words = functionValues[functionName];
|
std::vector<std::vector<std::string>> words = functionValues[functionName];
|
||||||
|
|
||||||
unordered_map<string, boost::any> variableValues = {};
|
unordered_map<string, boost::any> variableValues = {};
|
||||||
|
|
||||||
vector<string> args = words[0]; // This causes problem in linux
|
std::vector<std::string> funcArgs = words[0]; // This causes problem in linux
|
||||||
|
|
||||||
for (int i = 0; i < (int)inputVarVals.size(); i++)
|
for (int i = 0; i < (int)inputVarVals.size(); i++)
|
||||||
{
|
{
|
||||||
if(i < args.size())
|
if(i < funcArgs.size())
|
||||||
{
|
{
|
||||||
variableValues[args[i]] = inputVarVals[i];
|
variableValues[funcArgs[i]] = inputVarVals[i];
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
cout << functionName + " \x1B[33m" << args[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
cout << functionName + " \x1B[33m" << funcArgs[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEVELOPER_MESSAGES
|
|
||||||
InterpreterLog("Iterate");
|
|
||||||
#endif
|
|
||||||
//Iterate through all lines in function
|
//Iterate through all lines in function
|
||||||
for (int lineNum = 1; lineNum < (int)words.size(); lineNum++)
|
for (int lineNum = 1; lineNum < (int)words.size(); lineNum++)
|
||||||
{
|
{
|
||||||
@ -581,6 +579,9 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
|
|||||||
int parseSlang(string script)
|
int parseSlang(string script)
|
||||||
{
|
{
|
||||||
script = replace(script, " ", "\t");
|
script = replace(script, " ", "\t");
|
||||||
|
#if DEVELOPER_MESSAGES
|
||||||
|
InterpreterLog("Contents:\n" + script);
|
||||||
|
#endif
|
||||||
|
|
||||||
vector<string> lines = split(script, '\n');
|
vector<string> lines = split(script, '\n');
|
||||||
vector<vector<string>> words;
|
vector<vector<string>> words;
|
||||||
@ -600,6 +601,9 @@ int parseSlang(string script)
|
|||||||
vector<vector<string>> functionContents;
|
vector<vector<string>> functionContents;
|
||||||
|
|
||||||
string functName = split(words[lineNum][1], '(')[0];
|
string functName = split(words[lineNum][1], '(')[0];
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script function " + functName + "...");
|
||||||
|
#endif
|
||||||
|
|
||||||
string args = "";
|
string args = "";
|
||||||
if (indexInStr(unWrapVec(words[lineNum]), ')') - indexInStr(unWrapVec(words[lineNum]), '(') > 1)
|
if (indexInStr(unWrapVec(words[lineNum]), ')') - indexInStr(unWrapVec(words[lineNum]), '(') > 1)
|
||||||
@ -624,14 +628,30 @@ int parseSlang(string script)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (words[lineNum][0] == "string")
|
if (words[lineNum][0] == "string"){
|
||||||
globalVariableValues[words[lineNum][1]] = StringRaw(words[lineNum][3]);
|
globalVariableValues[words[lineNum][1]] = StringRaw(words[lineNum][3]);
|
||||||
else if (words[lineNum][0] == "int")
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words[lineNum][0] == "int"){
|
||||||
globalVariableValues[words[lineNum][1]] = stoi(words[lineNum][3]);
|
globalVariableValues[words[lineNum][1]] = stoi(words[lineNum][3]);
|
||||||
else if (words[lineNum][0] == "float")
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words[lineNum][0] == "float"){
|
||||||
globalVariableValues[words[lineNum][1]] = stof(words[lineNum][3]);
|
globalVariableValues[words[lineNum][1]] = stof(words[lineNum][3]);
|
||||||
else if (words[lineNum][0] == "bool")
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words[lineNum][0] == "bool"){
|
||||||
globalVariableValues[words[lineNum][1]] = stob(words[lineNum][3]);
|
globalVariableValues[words[lineNum][1]] = stob(words[lineNum][3]);
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
//else
|
//else
|
||||||
// LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum));
|
// LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum));
|
||||||
}
|
}
|
||||||
@ -653,8 +673,8 @@ int main(int argc, char* argv[])
|
|||||||
functionValues = builtinFunctionValues;
|
functionValues = builtinFunctionValues;
|
||||||
globalVariableValues = builtinVarVals;
|
globalVariableValues = builtinVarVals;
|
||||||
|
|
||||||
stringstream scriptString;
|
std::string scriptTextContents;
|
||||||
#if EXAMPLE_PROJECT == false
|
|
||||||
// If scriptname is supplied and not in developer mode
|
// If scriptname is supplied and not in developer mode
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
@ -665,22 +685,40 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
||||||
#if UNIX
|
#if UNIX
|
||||||
|
// Get script contents
|
||||||
|
auto ss = ostringstream{};
|
||||||
|
ifstream input_file(scriptPath);
|
||||||
|
ss << input_file.rdbuf();
|
||||||
|
scriptTextContents = ss.str();
|
||||||
|
#if DEVELOPER_MESSAGES
|
||||||
|
InterpreterLog("Gather script contents...");
|
||||||
|
#endif
|
||||||
|
|
||||||
chdir(projectDirectory.c_str());
|
chdir(projectDirectory.c_str());
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Change directory to " + projectDirectory + "...");
|
InterpreterLog("Change directory to " + projectDirectory + "...");
|
||||||
#endif
|
#endif
|
||||||
|
#if DEVELOPER_MESSAGES
|
||||||
|
string newPath = filesystem::current_path();
|
||||||
|
InterpreterLog("Current working directory is " + newPath);
|
||||||
|
#endif
|
||||||
#elif WINDOWS
|
#elif WINDOWS
|
||||||
|
// Get script contents
|
||||||
|
ifstream script(scriptPath);
|
||||||
|
stringstream scriptString;
|
||||||
|
scriptString << script.rdbuf();
|
||||||
|
scriptTextContents = scriptString.str();
|
||||||
|
#if DEVELOPER_MESSAGES
|
||||||
|
InterpreterLog("Gather script contents...");
|
||||||
|
#endif
|
||||||
|
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
std::wstring wide = converter.from_bytes(projectDirectory);
|
std::wstring wide = converter.from_bytes(projectDirectory);
|
||||||
LPCWSTR s = wide.c_str();
|
LPCWSTR s = wide.c_str();
|
||||||
SetCurrentDirectory(s);
|
SetCurrentDirectory(s);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Get script contents
|
|
||||||
ifstream script(scriptPath);
|
|
||||||
scriptString << script.rdbuf();
|
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Gather script contents...");
|
InterpreterLog("Change directory to " + projectDirectory + "...");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -689,33 +727,13 @@ int main(int argc, char* argv[])
|
|||||||
//system("pause");
|
//system("pause");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// If in developer mode
|
|
||||||
std::string scriptPath = "./Pong-Example-Project/script.slg";
|
|
||||||
#if DEVELOPER_MESSAGES == true
|
|
||||||
cout << scriptPath << endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
|
||||||
#if UNIX
|
|
||||||
//chdir(projectDirectory.c_str());
|
|
||||||
#elif WINDOWS
|
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
|
||||||
std::wstring wide = converter.from_bytes(projectDirectory);
|
|
||||||
LPCWSTR s = wide.c_str();
|
|
||||||
SetCurrentDirectory(s);
|
|
||||||
#endif
|
|
||||||
// Get script contents
|
|
||||||
ifstream script(scriptPath);
|
|
||||||
scriptString << script.rdbuf();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//system("pause");
|
//system("pause");
|
||||||
|
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Parsing...");
|
InterpreterLog("Parsing...");
|
||||||
#endif
|
#endif
|
||||||
parseSlang(scriptString.str());
|
parseSlang(scriptTextContents);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -288,7 +288,7 @@ boost::any SLBFunction(const string& name, const vector<boost::any>& args)
|
|||||||
any_cast<Sprite>(args[0]).Load();
|
any_cast<Sprite>(args[0]).Load();
|
||||||
else if (name == "SLB.Graphics.Text")
|
else if (name == "SLB.Graphics.Text")
|
||||||
{
|
{
|
||||||
Text t(StringRaw(AnyAsString(args[0])), StringRaw(AnyAsString(args[1])), any_cast<Vec2>(args[2]), AnyAsFloat(args[3]), AnyAsFloat(args[4]), AnyAsFloat(args[5]), AnyAsFloat(args[6]), AnyAsFloat(args[7]));
|
Text t(StringRaw(AnyAsString(args[0])), StringRaw(AnyAsString(args[1])), any_cast<Vec2>(args[2]), AnyAsFloat(args[3]), AnyAsFloat(args[4]), AnyAsInt(args[5]), AnyAsInt(args[6]), AnyAsInt(args[7]));
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else if (name == "SLB.Graphics.DrawText")
|
else if (name == "SLB.Graphics.DrawText")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user