Add new Lua function to load CSV file, utilize new function to correctly load , inside field values (closes #2124)

This commit is contained in:
Alexander Bock
2023-02-28 10:49:23 -07:00
parent 32af3cc675
commit 5b29fb045a
5 changed files with 101 additions and 68 deletions

View File

@@ -23,6 +23,7 @@
****************************************************************************************/
#include <openspace/openspace.h>
#include <ghoul/misc/csvreader.h>
namespace {
@@ -206,4 +207,23 @@ namespace {
return res;
}
/**
* Loads the CSV file provided as a parameter and returns it as a vector containing the
* values of the each row. The inner vector has the same number of values as the CSV has
* columns. The second parameter controls whether the first entry in the returned outer
* vector is containing the names of the columns
*/
[[codegen::luawrap]] std::vector<std::vector<std::string>> readCSVFile(
std::filesystem::path file,
bool includeFirstLine = false)
{
if (!std::filesystem::exists(file) || !std::filesystem::is_regular_file(file)) {
throw ghoul::lua::LuaError(fmt::format("Could not find file {}", file));
}
std::vector<std::vector<std::string>> res =
ghoul::loadCSVFile(file.string(), includeFirstLine);
return res;
}
#include "openspaceengine_lua_codegen.cpp"