comparison examples/js-font/main.cpp @ 188:0cecdadfb5c4

Misc: rework javascript bindings, closes #916 While here, create new test libraries for future unit tests.
author David Demelier <markand@malikania.fr>
date Wed, 24 Oct 2018 21:13:12 +0200
parents 3107ce017c3a
children f28cb6d04731
comparison
equal deleted inserted replaced
187:eaa7f85bfc22 188:0cecdadfb5c4
18 18
19 #include <chrono> 19 #include <chrono>
20 #include <iostream> 20 #include <iostream>
21 #include <thread> 21 #include <thread>
22 22
23 #include <malikania/locator.hpp>
24
25 #include <malikania/client/loader.hpp>
26
23 #include <malikania/js_client_resources_loader.hpp> 27 #include <malikania/js_client_resources_loader.hpp>
24 #include <malikania/js_font.hpp> 28 #include <malikania/js_font.hpp>
25 #include <malikania/js_window.hpp> 29 #include <malikania/js_window.hpp>
26 #include <malikania/locator.hpp>
27 30
28 using namespace std::chrono_literals; 31 using namespace std::chrono_literals;
29 32
30 using namespace mlk; 33 using namespace mlk;
31 using namespace mlk::client; 34 using namespace mlk::client;
35 using namespace mlk::duk;
32 36
33 void basic(dukx_context& ctx) 37 void basic(duk_context* ctx)
34 { 38 {
35 auto ret = duk_peval_string(ctx, 39 const auto ret = duk_peval_string(ctx,
36 "w = new Malikania.Window();" 40 "w = new Malikania.Window();"
37 "f = new Malikania.Font('DejaVuSans.ttf', 10);" 41 "f = new Malikania.Font('DejaVuSans.ttf', 10);"
38 "w.setDrawingColor('lightskyblue');" 42 "w.setDrawingColor('lightskyblue');"
39 "w.clear();" 43 "w.clear();"
40 "s = 'The world is Malikania.';" 44 "s = 'The world is Malikania.';"
43 "w.drawText(s, f, { x: 320 - (c.width / 2), y: 240 - (c.height / 2) });" 47 "w.drawText(s, f, { x: 320 - (c.width / 2), y: 240 - (c.height / 2) });"
44 "w.present();" 48 "w.present();"
45 ); 49 );
46 50
47 if (ret != 0) 51 if (ret != 0)
48 throw dukx_get_exception(ctx, -1); 52 throw get_stack(ctx, -1);
49 53
50 std::this_thread::sleep_for(3s); 54 std::this_thread::sleep_for(3s);
51 } 55 }
52 56
53 int main() 57 int main()
54 { 58 {
55 try { 59 try {
56 mlk::directory_locator locator(CMAKE_CURRENT_SOURCE_DIR "/resources"); 60 directory_locator locator(CMAKE_CURRENT_SOURCE_DIR "/resources");
57 mlk::client::loader loader(locator); 61 client::loader loader(locator);
58 dukx_context ctx; 62 context ctx;
59 63
60 duk_push_object(ctx); 64 duk_push_object(ctx);
61 duk_put_global_string(ctx, "Malikania"); 65 duk_put_global_string(ctx, "Malikania");
62 dukx_put_client_loader(ctx, loader);
63 dukx_load_font(ctx);
64 dukx_load_window(ctx);
65 66
67 load_font_api(ctx);
68 load_window_api(ctx);
69 put(ctx, loader);
66 basic(ctx); 70 basic(ctx);
67 } catch (const std::exception& ex) { 71 } catch (const std::exception& ex) {
68 std::cerr << ex.what() << std::endl; 72 std::cerr << ex.what() << std::endl;
69 return 1; 73 return 1;
70 } 74 }