build(wasm): libconfig now builds and works in wasm
This commit is contained in:
4
examples/config_example.yml
Normal file
4
examples/config_example.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
men: ["John Smith", "Bill Jones"]
|
||||
women:
|
||||
- Karol Boudreaux
|
||||
- Emily Boudreaux
|
||||
2
examples/meson.build
Normal file
2
examples/meson.build
Normal file
@@ -0,0 +1,2 @@
|
||||
executable('simple_config_test', 'simple.cpp', dependencies: [config_dep])
|
||||
executable('simple_config_wasm_test', 'wasm.cpp', dependencies: [config_dep])
|
||||
35
examples/simple.cpp
Normal file
35
examples/simple.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "fourdst/config/config.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
std::string get_validated_filename(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <input_file>" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::filesystem::path const file_path{ argv[1] };
|
||||
|
||||
if (not std::filesystem::exists(file_path) || not std::filesystem::is_regular_file(file_path)) {
|
||||
std::cout << "Error: File does not exist or is not a regular file." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return file_path.string();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
fourdst::config::Config& config = fourdst::config::Config::getInstance();
|
||||
|
||||
std::string filename = get_validated_filename(argc, argv);
|
||||
config.loadConfig(filename);
|
||||
|
||||
auto men = config.get<std::vector<std::string>>("men", {});
|
||||
|
||||
for (const auto& name : men) {
|
||||
std::cout << "men are " << name << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
19
examples/wasm.cpp
Normal file
19
examples/wasm.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "fourdst/config/config.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
fourdst::config::Config& config = fourdst::config::Config::getInstance();
|
||||
|
||||
config.loadConfig("/input.yaml");
|
||||
|
||||
auto men = config.get<std::vector<std::string>>("men", {});
|
||||
|
||||
for (const auto& name : men) {
|
||||
std::cout << "men are " << name << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user