C++20 Port #5

Merged
kayomn merged 35 commits from cpp-port into main 2023-02-20 02:33:45 +01:00
1 changed files with 22 additions and 7 deletions
Showing only changes of commit c45a270a0b - Show all commits

View File

@ -16,8 +16,9 @@ extern "C" int main(int argc, char const * const * argv) {
bool is_config_loaded{false}; bool is_config_loaded{false};
system.res_fs().read_file(config_path, [&](coral::readable const & file) { system.res_fs().read_file(config_path, [&](coral::readable const & file) {
kym::vm vm{&system.thread_safe_allocator(), coral::allocator * const allocator{&system.thread_safe_allocator()};
[&system](coral::slice<char const> const & error_message) {
kym::vm vm{allocator, [&system](coral::slice<char const> const & error_message) {
system.log(app::log_level::error, error_message); system.log(app::log_level::error, error_message);
}}; }};
@ -27,7 +28,7 @@ extern "C" int main(int argc, char const * const * argv) {
return; return;
} }
coral::stack<coral::u8> script_source{&system.thread_safe_allocator()}; coral::stack<coral::u8> script_source{allocator};
coral::u8 stream_buffer[1024]{0}; coral::u8 stream_buffer[1024]{0};
if (!coral::stream(coral::sequence_writer{&script_source}, file, stream_buffer).is_ok()) if (!coral::stream(coral::sequence_writer{&script_source}, file, stream_buffer).is_ok())
@ -51,7 +52,7 @@ extern "C" int main(int argc, char const * const * argv) {
vm.with_object(config.get_field("title"), [&](kym::bound_object & title) { vm.with_object(config.get_field("title"), [&](kym::bound_object & title) {
coral::stack<coral::u8, 128> title_buffer{&system.thread_safe_allocator()}; coral::stack<coral::u8, 128> title_buffer{&system.thread_safe_allocator()};
if (!title.stringify(coral::sequence_writer(&title_buffer)).is_ok()) { if (!title.stringify(coral::sequence_writer{&title_buffer}).is_ok()) {
system.log(app::log_level::error, system.log(app::log_level::error,
"failed to decode `title` property of config"); "failed to decode `title` property of config");
@ -64,7 +65,21 @@ extern "C" int main(int argc, char const * const * argv) {
}); });
}); });
if (!is_config_loaded) return coral::u8_max; if (!is_config_loaded) {
coral::stack<coral::u8> error_message{&system.thread_safe_allocator()};
{
coral::sequence_writer error_writer{&error_message};
if (!error_writer(coral::slice{"failed to load "}.as_bytes()).is_ok())
return coral::u8_max;
if (!error_writer(config_path.as_slice().as_bytes()).is_ok())
return coral::u8_max;
}
return coral::u8_max;
}
// app::canvas canvas_2d(); // app::canvas canvas_2d();