mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-19 19:39:30 -06:00
Add new Lua function to load CSV file, utilize new function to correctly load , inside field values (closes #2124)
This commit is contained in:
@@ -1689,7 +1689,8 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
|
||||
codegen::lua::DownloadFile,
|
||||
codegen::lua::CreateSingleColorImage,
|
||||
codegen::lua::IsMaster,
|
||||
codegen::lua::Version
|
||||
codegen::lua::Version,
|
||||
codegen::lua::ReadCSVFile
|
||||
},
|
||||
{
|
||||
absPath("${SCRIPTS}/core_scripts.lua")
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user