mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-11 16:22:12 +00:00
Porting code to linux
This commit is contained in:
parent
c5c2230736
commit
fa870f46d5
@ -2,6 +2,17 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#define DEVELOPER_MESSAGES true
|
||||
#define EXAMPLE_PROJECT false
|
||||
|
||||
#if defined(__unix__)
|
||||
#define UNIX true
|
||||
#define WINDOWS false
|
||||
#elif defined(_MSC_VER)
|
||||
#define UNIX false
|
||||
#define WINDOWS true
|
||||
#endif
|
||||
|
||||
#include <regex>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
@ -12,9 +23,9 @@
|
||||
#include <stdio.h>
|
||||
#include <codecvt>
|
||||
|
||||
#if defined(__unix__)
|
||||
#if UNIX
|
||||
#include <unistd.h>
|
||||
#elif defined(_MSC_VER)
|
||||
#elif WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
@ -26,9 +37,6 @@
|
||||
|
||||
#include "SLB.h"
|
||||
|
||||
#define DEVELOPER_MESSAGES true
|
||||
#define EXAMPLE_PROJECT false
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
@ -536,15 +544,23 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
|
||||
vector<vector<string>> words = functionValues[functionName];
|
||||
|
||||
unordered_map<string, boost::any> variableValues = {};
|
||||
vector<string> args = words[0];
|
||||
for (int i = 0; i < (int)inputVarVals.size(); i++) {
|
||||
|
||||
variableValues[args[i]] = inputVarVals[i];
|
||||
|
||||
vector<string> args = words[0]; // This causes problem in linux
|
||||
|
||||
for (int i = 0; i < (int)inputVarVals.size(); i++)
|
||||
{
|
||||
if(i < args.size())
|
||||
{
|
||||
variableValues[args[i]] = inputVarVals[i];
|
||||
#if DEVELOPER_MESSAGES == true
|
||||
cout << functionName + " \x1B[33m" << args[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
||||
cout << functionName + " \x1B[33m" << args[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if DEVELOPER_MESSAGES
|
||||
InterpreterLog("Iterate");
|
||||
#endif
|
||||
//Iterate through all lines in function
|
||||
for (int lineNum = 1; lineNum < (int)words.size(); lineNum++)
|
||||
{
|
||||
@ -571,6 +587,9 @@ int parseSlang(string script)
|
||||
for (int i = 0; i < (int)lines.size(); i++)
|
||||
words.push_back(split(lines[i], ' '));
|
||||
|
||||
#if DEVELOPER_MESSAGES
|
||||
InterpreterLog("Gather variables & functions...");
|
||||
#endif
|
||||
// First go through entire script and iterate through all types to see if line is a variable
|
||||
// or function declaration, then store it with it's value
|
||||
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
|
||||
@ -618,6 +637,9 @@ int parseSlang(string script)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEVELOPER_MESSAGES
|
||||
InterpreterLog("Start Main()");
|
||||
#endif
|
||||
// Executes main, which is the starting function
|
||||
ExecuteFunction("Main", vector<boost::any> {});
|
||||
|
||||
@ -637,16 +659,19 @@ int main(int argc, char* argv[])
|
||||
if (argc > 1)
|
||||
{
|
||||
std::string scriptPath = argv[1];
|
||||
#if DEVELOPER_MESSAGES == true
|
||||
#if DEVELOPER_MESSAGES
|
||||
cout << scriptPath << endl;
|
||||
#endif
|
||||
|
||||
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
||||
#if UNIX
|
||||
chdir(projectDirectory.c_str());
|
||||
#if DEVELOPER_MESSAGES
|
||||
InterpreterLog("Change directory to " + projectDirectory + "...");
|
||||
#endif
|
||||
#elif WINDOWS
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wide = converter.from_bytes(projectDirectory);
|
||||
|
||||
#if defined(__unix__)
|
||||
chdir(projectDirectory.c_str());
|
||||
#elif defined(_MSC_VER)
|
||||
LPCWSTR s = wide.c_str();
|
||||
SetCurrentDirectory(s);
|
||||
#endif
|
||||
@ -654,6 +679,9 @@ int main(int argc, char* argv[])
|
||||
// Get script contents
|
||||
ifstream script(scriptPath);
|
||||
scriptString << script.rdbuf();
|
||||
#if DEVELOPER_MESSAGES
|
||||
InterpreterLog("Gather script contents...");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -667,14 +695,14 @@ int main(int argc, char* argv[])
|
||||
#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);
|
||||
|
||||
#if defined(__unix__)
|
||||
chdir(projectDirectory.c_str());
|
||||
#elif defined(_MSC_VER)
|
||||
LPCSTR s = projectDirectory.c_str();
|
||||
LPCWSTR s = wide.c_str();
|
||||
SetCurrentDirectory(s);
|
||||
#endif
|
||||
// Get script contents
|
||||
@ -684,6 +712,9 @@ int main(int argc, char* argv[])
|
||||
|
||||
//system("pause");
|
||||
|
||||
#if DEVELOPER_MESSAGES
|
||||
InterpreterLog("Parsing...");
|
||||
#endif
|
||||
parseSlang(scriptString.str());
|
||||
|
||||
return 0;
|
||||
|
||||
@ -286,6 +286,8 @@ bool any_compare(const boost::any& a, const boost::any& b)
|
||||
// If it is a Vec2, then compare separately after converted
|
||||
else if (aType == 5)
|
||||
return any_cast<Vec2>(a) == any_cast<Vec2>(b);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
#include <ctime>
|
||||
#include <math.h>
|
||||
|
||||
#define DEVELOPER_MESSAGES false
|
||||
//#define DEVELOPER_MESSAGES false
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
@ -57,7 +57,7 @@ int InterpreterLog(const string& logText)
|
||||
|
||||
tm bt{};
|
||||
#if defined(__unix__)
|
||||
localtime_r(&timer, &bt);
|
||||
//localtime_r(&timer, &bt);
|
||||
#elif defined(_MSC_VER)
|
||||
localtime_s(&bt, &timer);
|
||||
#else
|
||||
@ -66,9 +66,12 @@ int InterpreterLog(const string& logText)
|
||||
bt = *localtime(&timer);
|
||||
#endif
|
||||
|
||||
int Hour = bt.tm_hour;
|
||||
int Min = bt.tm_min;
|
||||
int Sec = bt.tm_sec;
|
||||
//int Hour = bt.tm_hour;
|
||||
//int Min = bt.tm_min;
|
||||
//int Sec = bt.tm_sec;
|
||||
int Hour = 0;
|
||||
int Min = 0;
|
||||
int Sec = 0;
|
||||
|
||||
cout << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mSlang: \x1B[32m" << logText << "\033[0m\t\t" << endl;
|
||||
return 1;
|
||||
@ -80,7 +83,7 @@ int LogCriticalError(const string& errorText)
|
||||
|
||||
tm bt{};
|
||||
#if defined(__unix__)
|
||||
localtime_r(&timer, &bt);
|
||||
//localtime_r(&timer, &bt);
|
||||
#elif defined(_MSC_VER)
|
||||
localtime_s(&bt, &timer);
|
||||
#else
|
||||
@ -89,9 +92,12 @@ int LogCriticalError(const string& errorText)
|
||||
bt = *localtime(&timer);
|
||||
#endif
|
||||
|
||||
int Hour = bt.tm_hour;
|
||||
int Min = bt.tm_min;
|
||||
int Sec = bt.tm_sec;
|
||||
//int Hour = bt.tm_hour;
|
||||
//int Min = bt.tm_min;
|
||||
//int Sec = bt.tm_sec;
|
||||
int Hour = 0;
|
||||
int Min = 0;
|
||||
int Sec = 0;
|
||||
|
||||
cerr << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mSlang: \x1B[31mERROR: " << errorText << "\033[0m\t\t" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
@ -188,7 +194,7 @@ int GetBuiltins(std::string s)
|
||||
string functName = split(words[lineNum][1], '(')[0];
|
||||
|
||||
#if DEVELOPER_MESSAGES == true
|
||||
InterpreterLog("Load builtin function " + functName);
|
||||
InterpreterLog("Load builtin function " + functName + "...");
|
||||
#endif
|
||||
|
||||
string args = "";
|
||||
@ -217,28 +223,28 @@ int GetBuiltins(std::string s)
|
||||
{
|
||||
builtinVarVals[words[lineNum][1]] = StringRaw(words[lineNum][3]);
|
||||
#if DEVELOPER_MESSAGES == true
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
|
||||
#endif
|
||||
}
|
||||
else if (words[lineNum][0] == "int")
|
||||
{
|
||||
builtinVarVals[words[lineNum][1]] = stoi(words[lineNum][3]);
|
||||
#if DEVELOPER_MESSAGES == true
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
|
||||
#endif
|
||||
}
|
||||
else if (words[lineNum][0] == "float")
|
||||
{
|
||||
builtinVarVals[words[lineNum][1]] = stof(words[lineNum][3]);
|
||||
#if DEVELOPER_MESSAGES == true
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
|
||||
#endif
|
||||
}
|
||||
else if (words[lineNum][0] == "bool")
|
||||
{
|
||||
builtinVarVals[words[lineNum][1]] = stob(words[lineNum][3]);
|
||||
#if DEVELOPER_MESSAGES == true
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
|
||||
#endif
|
||||
}
|
||||
//else
|
||||
|
||||
@ -217,6 +217,7 @@ public:
|
||||
return x;
|
||||
if (componentName == "y")
|
||||
return y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vec2 EditSubComponent(std::string componentName, std::string oper, boost::any otherVal)
|
||||
@ -412,6 +413,7 @@ public:
|
||||
return scale.x;
|
||||
if (componentName == "scale.y")
|
||||
return scale.y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Sprite EditSubComponent(std::string componentName, std::string oper, boost::any otherVal)
|
||||
@ -527,7 +529,7 @@ public:
|
||||
|
||||
int Load()
|
||||
{
|
||||
SDL_Color color = { r, g, b };
|
||||
SDL_Color color = { (Uint8)r, (Uint8)g, (Uint8)b };
|
||||
|
||||
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
||||
|
||||
@ -549,7 +551,7 @@ public:
|
||||
|
||||
int Update()
|
||||
{
|
||||
SDL_Color color = { r, g, b };
|
||||
SDL_Color color = { (Uint8)r, (Uint8)g, (Uint8)b };
|
||||
|
||||
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
||||
|
||||
@ -596,6 +598,7 @@ public:
|
||||
return content;
|
||||
if (componentName == "pathToFont")
|
||||
return pathToFont;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Text EditSubComponent(const std::string componentName, const std::string oper, const boost::any otherVal)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user