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