Add VenusParser class, zepha-venus submodule.

master
Nicole Collings 2020-02-10 11:19:55 -08:00
parent 17380d83fa
commit d7aea41234
7 changed files with 82 additions and 6 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "zepha-venus"]
path = zepha-venus
url = https://github.com/Aurailus/zepha-venus

View File

@ -279,6 +279,6 @@ set(ZEPHA_SRC
util/net/Serializer.h
util/net/Deserializer.h
lua/api/type/ServerLocalLuaEntity.cpp
lua/api/type/ServerLocalLuaEntity.h lua/api/modules/register_item.h lua/api/modules/register_biome.h lua/api/modules/delay.h lua/api/modules/register_block.h lua/api/modules/register_blockmodel.h lua/api/modules/register_entity.h game/scene/world/World.cpp game/scene/world/World.h lua/api/modules/set_block.h lua/api/modules/get_block.h lua/api/modules/remove_block.h lua/register/RegisterBiomes.h lua/register/RegisterBlocks.h lua/register/RegisterItems.h lua/register/RegisterKeybinds.h lua/api/type/LocalLuaAnimationManager.cpp lua/api/type/LocalLuaAnimationManager.h lua/api/type/cLocalLuaAnimationManager.h game/scene/world/Schematic.cpp game/scene/world/Schematic.h)
lua/api/type/ServerLocalLuaEntity.h lua/api/modules/register_item.h lua/api/modules/register_biome.h lua/api/modules/delay.h lua/api/modules/register_block.h lua/api/modules/register_blockmodel.h lua/api/modules/register_entity.h game/scene/world/World.cpp game/scene/world/World.h lua/api/modules/set_block.h lua/api/modules/get_block.h lua/api/modules/remove_block.h lua/register/RegisterBiomes.h lua/register/RegisterBlocks.h lua/register/RegisterItems.h lua/register/RegisterKeybinds.h lua/api/type/LocalLuaAnimationManager.cpp lua/api/type/LocalLuaAnimationManager.h lua/api/type/cLocalLuaAnimationManager.h game/scene/world/Schematic.cpp game/scene/world/Schematic.h lua/VenusParser.cpp lua/VenusParser.h)
add_library (Zepha_Core ${ZEPHA_SRC})

View File

@ -4,7 +4,6 @@
#include "TextureAtlas.h"
#include <stb_image/stb_image.h>
#include <stb_image/stb_image_write.h>
TextureAtlas::TextureAtlas(unsigned int width, unsigned int height) :
pixelSize(width, (height == 0 ? width : height)),

40
src/lua/VenusParser.cpp Normal file
View File

@ -0,0 +1,40 @@
//
// Created by aurailus on 2020-02-09.
//
#include "VenusParser.h"
std::string VenusParser::parse(std::string src) {
#ifdef _WIN32
const static char* EXECUTABLE_NAME = "zepha-venus-win.exe";
#elif __APPLE__
const static char* EXECUTABLE_NAME = "zepha-venus-macos";
#else
const static char* EXECUTABLE_NAME = "zepha-venus-linux";
#endif
const static std::string path = "../zepha-venus/" + std::string(EXECUTABLE_NAME);
const static bool exists = cf_file_exists(path.data());
if (!exists) throw std::string("Trying to compile a venus file when zepha-venus has not been built!");
std::string call = path + " " + src;
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(call.data(), "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed!");
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
const static std::string errorHeader = "--ZEPHA_PARSING_ERROR--";
if (result.length() > errorHeader.length() && result.substr(0, errorHeader.length()) == errorHeader) {
throw std::string(result.substr(errorHeader.length() + 1, result.length() - errorHeader.length() - 1));
}
return result;
}

15
src/lua/VenusParser.h Normal file
View File

@ -0,0 +1,15 @@
//
// Created by aurailus on 2020-02-09.
//
#pragma once
#include <string>
#include <array>
#include <memory>
#include <cute_files/cute_files.h>
class VenusParser {
public:
static std::string parse(std::string src);
};

View File

@ -28,6 +28,7 @@
#include "../api/modules/remove_entity.h"
#include "../api/functions/sUpdateEntities.h"
#include "../VenusParser.h"
void ServerLuaParser::init(ServerDefs& defs, ServerWorld& world, std::string path) {
//Load Base Libraries
@ -188,7 +189,7 @@ std::vector<LuaMod> ServerLuaParser::createLuaMods(std::list<std::string> modDir
if (scannedFile.is_dir) dirsToScan.emplace_back(scannedFile.path);
else {
char *dot = strrchr(scannedFile.path, '.');
if (dot && strncmp(dot, ".lua", 4) == 0) {
if (dot && (strncmp(dot, ".lua", 4) == 0 || strncmp(dot, ".venus", 6) == 0)) {
luaFiles.emplace_back(scannedFile.path);
}
}
@ -226,12 +227,29 @@ std::vector<LuaMod> ServerLuaParser::createLuaMods(std::list<std::string> modDir
std::string modPath = file;
assert(rootPos != std::string::npos);
std::string fileStr = "";
modPath.erase(rootPos, root.length());
modPath.insert(0, conf.name);
modPath.resize(modPath.size() - 4);
std::ifstream t(file);
std::string fileStr((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
const static std::string venusSubstr = ".venus";
if (std::equal(venusSubstr.rbegin(), venusSubstr.rend(), file.rbegin())) {
modPath.resize(modPath.size() - 6);
try {
fileStr = VenusParser::parse(file);
}
catch (std::string e) {
std::cout << Log::err << "Error compiling Venus file '" << file << "':\n" << e << Log::endl;
exit(1);
}
}
else {
modPath.resize(modPath.size() - 4);
std::ifstream t(file);
fileStr = std::string((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
}
LuaModFile f {modPath, fileStr};
mod.files.push_back(f);

1
zepha-venus Submodule

@ -0,0 +1 @@
Subproject commit 33dab5bdad2f6b4daf74f9b0386c45c28386b5d8