diff tests/libclient/js-color/main.cpp @ 36:9af360f34c7d

Misc: use raw duktape API
author David Demelier <markand@malikania.fr>
date Wed, 10 Aug 2016 14:30:51 +0200
parents d4f5f7231b84
children a47a4477f347
line wrap: on
line diff
--- a/tests/libclient/js-color/main.cpp	Fri Jul 01 13:32:08 2016 +0200
+++ b/tests/libclient/js-color/main.cpp	Wed Aug 10 14:30:51 2016 +0200
@@ -24,14 +24,23 @@
 
 class TestColor : public testing::Test {
 protected:
-    duk::Context m_ctx;
+    UniqueContext m_ctx;
 
 public:
     TestColor()
     {
-        duk::putGlobal(m_ctx, "Malikania", duk::Object());
+        duk_push_object(m_ctx);
+        duk_put_global_string(m_ctx, "Malikania");
+        dukx_load_color(m_ctx);
+    }
 
-        loadMalikaniaColor(m_ctx);
+    int component(const char *name)
+    {
+        duk_get_global_string(m_ctx, name);
+        auto value = duk_require_int(m_ctx, -1);
+        duk_pop(m_ctx);
+
+        return value;
     }
 };
 
@@ -43,7 +52,7 @@
 TEST_F(TestColor, ConstructorNoArgs)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = Malikania.Color();"
             "r = c.red;"
             "g = c.green;"
@@ -51,14 +60,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(0, component("r"));
+        ASSERT_EQ(0, component("g"));
+        ASSERT_EQ(0, component("b"));
+        ASSERT_EQ(255, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -67,7 +75,7 @@
 TEST_F(TestColor, ConstructorString)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = Malikania.Color('white');"
             "r = c.red;"
             "g = c.green;"
@@ -75,14 +83,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(255, component("r"));
+        ASSERT_EQ(255, component("g"));
+        ASSERT_EQ(255, component("b"));
+        ASSERT_EQ(255, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -91,7 +98,7 @@
 TEST_F(TestColor, ConstructorStringRgb)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = Malikania.Color('#0000ff');"
             "r = c.red;"
             "g = c.green;"
@@ -99,14 +106,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(0, component("r"));
+        ASSERT_EQ(0, component("g"));
+        ASSERT_EQ(255, component("b"));
+        ASSERT_EQ(255, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -115,7 +121,7 @@
 TEST_F(TestColor, Constructor3Args)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = Malikania.Color(10, 20, 30);"
             "r = c.red;"
             "g = c.green;"
@@ -123,14 +129,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(10, component("r"));
+        ASSERT_EQ(20, component("g"));
+        ASSERT_EQ(30, component("b"));
+        ASSERT_EQ(255, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -139,7 +144,7 @@
 TEST_F(TestColor, Constructor4Args)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = Malikania.Color(10, 20, 30, 40);"
             "r = c.red;"
             "g = c.green;"
@@ -147,14 +152,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(10, component("r"));
+        ASSERT_EQ(20, component("g"));
+        ASSERT_EQ(30, component("b"));
+        ASSERT_EQ(40, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -163,7 +167,7 @@
 TEST_F(TestColor, ConstructorObjectNoAlpha)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = Malikania.Color({ red: 10, green: 20, blue: 30 });"
             "r = c.red;"
             "g = c.green;"
@@ -171,14 +175,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(10, component("r"));
+        ASSERT_EQ(20, component("g"));
+        ASSERT_EQ(30, component("b"));
+        ASSERT_EQ(255, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -187,7 +190,7 @@
 TEST_F(TestColor, ConstructorObjectAlpha)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });"
             "r = c.red;"
             "g = c.green;"
@@ -195,14 +198,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(10, component("r"));
+        ASSERT_EQ(20, component("g"));
+        ASSERT_EQ(30, component("b"));
+        ASSERT_EQ(40, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -214,7 +216,7 @@
      * Just one test, function parse the same way, only 'this' or a new object is returned.
      */
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "c = new Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });"
             "r = c.red;"
             "g = c.green;"
@@ -222,14 +224,13 @@
             "a = c.alpha;"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a"));
+        ASSERT_EQ(10, component("r"));
+        ASSERT_EQ(20, component("g"));
+        ASSERT_EQ(30, component("b"));
+        ASSERT_EQ(40, component("a"));
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -243,7 +244,7 @@
 TEST_F(TestColor, InvalidConstructorArg1)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color(null);"
             "} catch (e) {"
@@ -252,12 +253,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("TypeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -266,7 +270,7 @@
 TEST_F(TestColor, InvalidConstructorArg2)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color(10, null, 30);"
             "} catch (e) {"
@@ -275,12 +279,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("TypeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -289,7 +296,7 @@
 TEST_F(TestColor, InvalidConstructorRange1)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color(-1, 20, 30);"
             "} catch (e) {"
@@ -298,12 +305,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -312,7 +322,7 @@
 TEST_F(TestColor, InvalidConstructorRange2)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color(10, 20, 256);"
             "} catch (e) {"
@@ -321,12 +331,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -335,7 +348,7 @@
 TEST_F(TestColor, InvalidConstructorRange3)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color(10, 20, 30, 800);"
             "} catch (e) {"
@@ -344,12 +357,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -358,7 +374,7 @@
 TEST_F(TestColor, InvalidConstructorRange4)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color({ red: -1, green: 20, blue: 30 });"
             "} catch (e) {"
@@ -367,12 +383,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -381,7 +400,7 @@
 TEST_F(TestColor, InvalidConstructorRange5)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 800 });"
             "} catch (e) {"
@@ -390,12 +409,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -404,7 +426,7 @@
 TEST_F(TestColor, InvalidConstructorStringUnknown)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color('does not exist');"
             "} catch (e) {"
@@ -413,12 +435,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("Error", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -427,7 +452,7 @@
 TEST_F(TestColor, InvalidConstructorStringRgb)
 {
     try {
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  Malikania.Color('#ghijkl');"
             "} catch (e) {"
@@ -436,12 +461,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("Error", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -458,27 +486,39 @@
 TEST_F(TestColor, requireSuccess)
 {
     try {
-        duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret {
-            Color color = duk::require<Color>(ctx, 0);
+        duk_push_c_function(m_ctx, [] (auto ctx) {
+            Color color = dukx_require_color(ctx, 0);
 
-            duk::putGlobal(ctx, "r", static_cast<int>(color.red()));
-            duk::putGlobal(ctx, "g", static_cast<int>(color.green()));
-            duk::putGlobal(ctx, "b", static_cast<int>(color.blue()));
-            duk::putGlobal(ctx, "a", static_cast<int>(color.alpha()));
+            duk_push_uint(ctx, color.red());
+            duk_put_global_string(ctx, "r");
+            duk_push_uint(ctx, color.green());
+            duk_put_global_string(ctx, "g");
+            duk_push_uint(ctx, color.blue());
+            duk_put_global_string(ctx, "b");
+            duk_push_uint(ctx, color.alpha());
+            duk_put_global_string(ctx, "a");
 
             return 0;
-        }, 1});
+        }, 1);
+        duk_put_global_string(m_ctx, "draw");
 
-        auto ret = duk::pevalString(m_ctx, "draw('#ff0000');");
+        auto ret = duk_peval_string(m_ctx, "draw('#ff0000');");
+
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
-
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        duk_get_global_string(m_ctx, "r");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "g");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "b");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "a");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -487,13 +527,14 @@
 TEST_F(TestColor, requireFail)
 {
     try {
-        duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret {
-            duk::require<Color>(ctx, 0);
+        duk_push_c_function(m_ctx, [] (auto ctx) {
+            dukx_require_color(ctx, 0);
 
             return 0;
-        }, 1});
+        }, 1);
+        duk_put_global_string(m_ctx, "draw");
 
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  draw('#ghijkl');"
             "} catch (e) {"
@@ -502,12 +543,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("Error", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -516,13 +560,14 @@
 TEST_F(TestColor, requireFailAlpha)
 {
     try {
-        duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret {
-            duk::require<Color>(ctx, 0);
+        duk_push_c_function(m_ctx, [] (auto ctx) {
+            dukx_require_color(ctx, 0);
 
             return 0;
-        }, 1});
+        }, 1);
+        duk_put_global_string(m_ctx, "draw");
 
-        auto ret = duk::pevalString(m_ctx,
+        auto ret = duk_peval_string(m_ctx,
             "try {"
             "  draw({ red: 10, green: 20, blue: 30, alpha: 800 });"
             "} catch (e) {"
@@ -531,12 +576,15 @@
             "}"
         );
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name"));
-        ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct"));
+        duk_get_global_string(m_ctx, "name");
+        ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "correct");
+        ASSERT_TRUE(duk_to_boolean(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -552,27 +600,39 @@
 TEST_F(TestColor, getNormal)
 {
     try {
-        duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret {
-            Color color = duk::get<Color>(ctx, 0);
+        duk_push_c_function(m_ctx, [] (auto ctx) {
+            Color color = dukx_get_color(ctx, 0);
 
-            duk::putGlobal(ctx, "r", static_cast<int>(color.red()));
-            duk::putGlobal(ctx, "g", static_cast<int>(color.green()));
-            duk::putGlobal(ctx, "b", static_cast<int>(color.blue()));
-            duk::putGlobal(ctx, "a", static_cast<int>(color.alpha()));
+            duk_push_uint(ctx, color.red());
+            duk_put_global_string(ctx, "r");
+            duk_push_uint(ctx, color.green());
+            duk_put_global_string(ctx, "g");
+            duk_push_uint(ctx, color.blue());
+            duk_put_global_string(ctx, "b");
+            duk_push_uint(ctx, color.alpha());
+            duk_put_global_string(ctx, "a");
 
             return 0;
-        }, 1});
+        }, 1);
+        duk_put_global_string(m_ctx, "draw");
 
-        auto ret = duk::pevalString(m_ctx, "draw('#ff0000');");
+        auto ret = duk_peval_string(m_ctx, "draw('#ff0000');");
+
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
-
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        duk_get_global_string(m_ctx, "r");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "g");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "b");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "a");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -581,27 +641,39 @@
 TEST_F(TestColor, getAdjustRgb)
 {
     try {
-        duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret {
-            Color color = duk::get<Color>(ctx, 0);
+        duk_push_c_function(m_ctx, [] (auto ctx) {
+            Color color = dukx_get_color(ctx, 0);
 
-            duk::putGlobal(ctx, "r", static_cast<int>(color.red()));
-            duk::putGlobal(ctx, "g", static_cast<int>(color.green()));
-            duk::putGlobal(ctx, "b", static_cast<int>(color.blue()));
-            duk::putGlobal(ctx, "a", static_cast<int>(color.alpha()));
+            duk_push_uint(ctx, color.red());
+            duk_put_global_string(ctx, "r");
+            duk_push_uint(ctx, color.green());
+            duk_put_global_string(ctx, "g");
+            duk_push_uint(ctx, color.blue());
+            duk_put_global_string(ctx, "b");
+            duk_push_uint(ctx, color.alpha());
+            duk_put_global_string(ctx, "a");
 
             return 0;
-        }, 1});
+        }, 1);
+        duk_put_global_string(m_ctx, "draw");
 
-        auto ret = duk::pevalString(m_ctx, "draw('#ghijkl');");
+        auto ret = duk_peval_string(m_ctx, "draw('#ghijkl');");
+
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
-
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        duk_get_global_string(m_ctx, "r");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "g");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "b");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "a");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -610,27 +682,39 @@
 TEST_F(TestColor, getAdjustAll)
 {
     try {
-        duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret {
-            Color color = duk::get<Color>(ctx, 0);
+        duk_push_c_function(m_ctx, [] (auto ctx) {
+            Color color = dukx_get_color(ctx, 0);
 
-            duk::putGlobal(ctx, "r", static_cast<int>(color.red()));
-            duk::putGlobal(ctx, "g", static_cast<int>(color.green()));
-            duk::putGlobal(ctx, "b", static_cast<int>(color.blue()));
-            duk::putGlobal(ctx, "a", static_cast<int>(color.alpha()));
+            duk_push_uint(ctx, color.red());
+            duk_put_global_string(ctx, "r");
+            duk_push_uint(ctx, color.green());
+            duk_put_global_string(ctx, "g");
+            duk_push_uint(ctx, color.blue());
+            duk_put_global_string(ctx, "b");
+            duk_push_uint(ctx, color.alpha());
+            duk_put_global_string(ctx, "a");
 
             return 0;
-        }, 1});
+        }, 1);
+        duk_put_global_string(m_ctx, "draw");
 
-        auto ret = duk::pevalString(m_ctx, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });");
+        auto ret = duk_peval_string(m_ctx, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });");
+
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
-
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        duk_get_global_string(m_ctx, "r");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "g");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "b");
+        ASSERT_EQ(100U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "a");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }
@@ -639,27 +723,39 @@
 TEST_F(TestColor, getSomethingElse)
 {
     try {
-        duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret {
-            Color color = duk::get<Color>(ctx, 0);
+        duk_push_c_function(m_ctx, [] (auto ctx) {
+            Color color = dukx_get_color(ctx, 0);
 
-            duk::putGlobal(ctx, "r", static_cast<int>(color.red()));
-            duk::putGlobal(ctx, "g", static_cast<int>(color.green()));
-            duk::putGlobal(ctx, "b", static_cast<int>(color.blue()));
-            duk::putGlobal(ctx, "a", static_cast<int>(color.alpha()));
+            duk_push_uint(ctx, color.red());
+            duk_put_global_string(ctx, "r");
+            duk_push_uint(ctx, color.green());
+            duk_put_global_string(ctx, "g");
+            duk_push_uint(ctx, color.blue());
+            duk_put_global_string(ctx, "b");
+            duk_push_uint(ctx, color.alpha());
+            duk_put_global_string(ctx, "a");
 
             return 0;
-        }, 1});
+        }, 1);
+        duk_put_global_string(m_ctx, "draw");
 
-        auto ret = duk::pevalString(m_ctx, "draw(null);");
+        auto ret = duk_peval_string(m_ctx, "draw(null);");
+
+        if (ret != 0)
+            throw dukx_exception(m_ctx, -1);
 
-        if (ret != 0) {
-            throw duk::exception(m_ctx, -1);
-        }
-
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g"));
-        ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b"));
-        ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a"));
+        duk_get_global_string(m_ctx, "r");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "g");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "b");
+        ASSERT_EQ(0U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
+        duk_get_global_string(m_ctx, "a");
+        ASSERT_EQ(255U, duk_to_uint(m_ctx, -1));
+        duk_pop(m_ctx);
     } catch (const std::exception &ex) {
         FAIL() << ex.what();
     }