/* Copyright 2022, Michele Santullo * This file is part of duckticker. * * Wrenpp is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wrenpp is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with duckticker. If not, see . */ #include "bitcoinity_ticker_price.hpp" #include "configure.hpp" #include #include #include namespace { class MyWrenConfiguration : public wren::DefConfiguration { public: char* load_module_fn(wren::VM* vm, std::string_view module_name) { std::string_view wren_code; if (module_name == "bitcoinity") wren_code = duck::g_bitcoinity_wren_module; else if (module_name == "ticker_price") wren_code = duck::g_ticker_price_wren_module; else return nullptr; const std::size_t buff_sz = wren_code.size(); char* const buff = static_cast(MyWrenConfiguration::reallocate_fn(nullptr, buff_sz)); std::copy(wren_code.cbegin(), wren_code.cend(), buff); return buff; } }; std::string load_string_from_file (const std::string& path) { std::ifstream ifs(path); ifs >> std::noskipws; return std::string( std::istreambuf_iterator(ifs), std::istreambuf_iterator() ); } } //unnamed namespace int main() { using duck::TickerPrice; MyWrenConfiguration config; wren::VM vm(&config, nullptr); duck::register_bitcoinity_to_wren(vm); std::string main_script = load_string_from_file(std::string{duck::g_script_path} + "main.wren"); vm.interpret("main", main_script.c_str()); wren::call(vm, {"main", "the_app"}, "start"); return 0; }