Mercurial > irccd
changeset 656:2838134d69bf
Irccd: style (jsapi) #782
line wrap: on
line diff
--- a/libirccd-js/irccd/js/directory_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/directory_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -46,7 +46,7 @@ if (duk_get_type(ctx, -1) != DUK_TYPE_STRING) duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Directory object"); - auto ret = dukx_get<std::string>(ctx, -1); + const auto ret = dukx_get<std::string>(ctx, -1); if (ret.empty()) duk_error(ctx, DUK_ERR_TYPE_ERROR, "directory object has empty path"); @@ -75,12 +75,12 @@ else { // Check if it's a valid RegExp object. duk_get_global_string(ctx, "RegExp"); - auto is_regex = duk_instanceof(ctx, pattern_index, -1); + const auto is_regex = duk_instanceof(ctx, pattern_index, -1); duk_pop(ctx); if (is_regex) { duk_get_prop_string(ctx, pattern_index, "source"); - auto pattern = duk_to_string(ctx, -1); + const auto pattern = duk_to_string(ctx, -1); duk_pop(ctx); path = fs_util::find(base, std::regex(pattern), recursive); @@ -298,7 +298,7 @@ } // !namespace -std::string directory_jsapi::name() const +std::string directory_jsapi::get_name() const { return "Irccd.Directory"; }
--- a/libirccd-js/irccd/js/directory_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/directory_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class directory_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/libirccd-js/irccd/js/elapsed_timer_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/elapsed_timer_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -33,7 +33,7 @@ duk_push_this(ctx); duk_get_prop_string(ctx, -1, signature); - auto ptr = static_cast<boost::timer::cpu_timer*>(duk_to_pointer(ctx, -1)); + const auto ptr = static_cast<boost::timer::cpu_timer*>(duk_to_pointer(ctx, -1)); duk_pop_2(ctx); if (!ptr) @@ -125,7 +125,7 @@ } // !namespace -std::string elapsed_timer_jsapi::name() const +std::string elapsed_timer_jsapi::get_name() const { return "Irccd.ElapsedTimer"; }
--- a/libirccd-js/irccd/js/elapsed_timer_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/elapsed_timer_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class elapsed_timer_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/libirccd-js/irccd/js/file_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/file_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -77,7 +77,7 @@ */ duk_ret_t method_basename(duk_context* ctx) { - return dukx_push(ctx, fs_util::base_name(self(ctx)->path())); + return dukx_push(ctx, fs_util::base_name(self(ctx)->get_path())); } /* @@ -104,7 +104,7 @@ */ duk_ret_t method_dirname(duk_context* ctx) { - return dukx_push(ctx, fs_util::dir_name(self(ctx)->path())); + return dukx_push(ctx, fs_util::dir_name(self(ctx)->get_path())); } /* @@ -122,7 +122,7 @@ { duk_push_array(ctx); - std::FILE* fp = self(ctx)->handle(); + std::FILE* fp = self(ctx)->get_handle(); std::string buffer; std::array<char, 128> data; std::int32_t i = 0; @@ -130,7 +130,7 @@ while (std::fgets(&data[0], data.size(), fp) != nullptr) { buffer += data.data(); - auto pos = buffer.find('\n'); + const auto pos = buffer.find('\n'); if (pos != std::string::npos) { dukx_push(ctx, clear_crlf(buffer.substr(0, pos))); @@ -168,10 +168,10 @@ */ duk_ret_t method_read(duk_context* ctx) { - auto file = self(ctx); - auto amount = duk_is_number(ctx, 0) ? duk_get_int(ctx, 0) : -1; + const auto fp = self(ctx)->get_handle(); + const auto amount = duk_is_number(ctx, 0) ? duk_get_int(ctx, 0) : -1; - if (amount == 0 || file->handle() == nullptr) + if (amount == 0 || !fp) return 0; try { @@ -182,18 +182,18 @@ std::array<char, 128> buffer; std::size_t nread; - while ((nread = std::fread(&buffer[0], sizeof (buffer[0]), buffer.size(), file->handle())) > 0) { - if (std::ferror(file->handle())) + while ((nread = std::fread(&buffer[0], sizeof (buffer[0]), buffer.size(), fp)) > 0) { + if (std::ferror(fp)) dukx_throw(ctx, system_error()); std::copy(buffer.begin(), buffer.begin() + nread, std::back_inserter(data)); total += nread; } } else { - data.resize((std::size_t)amount); - total = std::fread(&data[0], sizeof (data[0]), (std::size_t)amount, file->handle()); + data.resize(static_cast<std::size_t>(amount)); + total = std::fread(&data[0], sizeof (data[0]), static_cast<std::size_t>(amount), fp); - if (std::ferror(file->handle())) + if (std::ferror(fp)) dukx_throw(ctx, system_error()); data.resize(total); @@ -220,11 +220,13 @@ */ duk_ret_t method_readline(duk_context* ctx) { - std::FILE* fp = self(ctx)->handle(); - std::string result; + auto fp = self(ctx)->get_handle(); if (fp == nullptr || std::feof(fp)) return 0; + + std::string result; + for (int ch; (ch = std::fgetc(fp)) != EOF && ch != '\n'; ) result += (char)ch; if (std::ferror(fp)) @@ -244,7 +246,7 @@ */ duk_ret_t method_remove(duk_context* ctx) { - if (::remove(self(ctx)->path().c_str()) < 0) + if (::remove(self(ctx)->get_path().c_str()) < 0) dukx_throw(ctx, system_error()); return 0; @@ -264,7 +266,7 @@ */ duk_ret_t method_seek(duk_context* ctx) { - auto fp = self(ctx)->handle(); + auto fp = self(ctx)->get_handle(); auto type = duk_require_int(ctx, 0); auto amount = duk_require_int(ctx, 1); @@ -292,7 +294,7 @@ auto file = self(ctx); struct stat st; - if (file->handle() == nullptr && ::stat(file->path().c_str(), &st) < 0) + if (file->get_handle() == nullptr && ::stat(file->get_path().c_str(), &st) < 0) dukx_throw(ctx, system_error()); else dukx_push(ctx, st); @@ -315,7 +317,7 @@ */ duk_ret_t method_tell(duk_context* ctx) { - auto fp = self(ctx)->handle(); + auto fp = self(ctx)->get_handle(); long pos; if (fp == nullptr) @@ -344,13 +346,13 @@ */ duk_ret_t method_write(duk_context* ctx) { - std::FILE* fp = self(ctx)->handle(); - std::string data = duk_require_string(ctx, 0); + auto fp = self(ctx)->get_handle(); + auto data = dukx_require<std::string>(ctx, 0); if (fp == nullptr) return 0; - auto nwritten = std::fwrite(data.c_str(), 1, data.length(), fp); + const auto nwritten = std::fwrite(data.c_str(), 1, data.length(), fp); if (std::ferror(fp)) dukx_throw(ctx, system_error()); @@ -552,7 +554,7 @@ } // !namespace -std::string file_jsapi::name() const +std::string file_jsapi::get_name() const { return "Irccd.File"; } @@ -598,7 +600,7 @@ duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a File object"); duk_get_prop_string(ctx, index, signature); - auto fp = static_cast<std::shared_ptr<file>*>(duk_to_pointer(ctx, -1)); + const auto fp = static_cast<std::shared_ptr<file>*>(duk_to_pointer(ctx, -1)); duk_pop(ctx); return *fp;
--- a/libirccd-js/irccd/js/file_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/file_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -112,7 +112,7 @@ * \return the path * \warning empty when constructed from the FILE constructor */ - inline const std::string& path() const noexcept + inline const std::string& get_path() const noexcept { return path_; } @@ -122,7 +122,7 @@ * * \return the handle or nullptr if the stream was closed */ - inline std::FILE* handle() noexcept + inline std::FILE* get_handle() noexcept { return stream_; } @@ -146,9 +146,9 @@ class file_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/libirccd-js/irccd/js/irccd_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/irccd_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -165,12 +165,12 @@ duk_get_global_string(ctx, "Irccd"); duk_get_prop_string(ctx, -1, "SystemError"); duk_remove(ctx, -2); - duk_push_int(ctx, errno_); + dukx_push(ctx, errno_); dukx_push(ctx, message_); duk_new(ctx, 2); } -std::string irccd_jsapi::name() const +std::string irccd_jsapi::get_name() const { return "Irccd"; } @@ -184,11 +184,11 @@ // Version. duk_push_object(plugin->context()); - duk_push_int(plugin->context(), IRCCD_VERSION_MAJOR); + dukx_push(plugin->context(), IRCCD_VERSION_MAJOR); duk_put_prop_string(plugin->context(), -2, "major"); - duk_push_int(plugin->context(), IRCCD_VERSION_MINOR); + dukx_push(plugin->context(), IRCCD_VERSION_MINOR); duk_put_prop_string(plugin->context(), -2, "minor"); - duk_push_int(plugin->context(), IRCCD_VERSION_PATCH); + dukx_push(plugin->context(), IRCCD_VERSION_PATCH); duk_put_prop_string(plugin->context(), -2, "patch"); duk_put_prop_string(plugin->context(), -2, "version"); @@ -217,12 +217,12 @@ duk_put_global_string(plugin->context(), "\xff""\xff""irccd-ref"); } -irccd& dukx_get_irccd(duk_context *ctx) +irccd& dukx_type_traits<irccd>::self(duk_context *ctx) { dukx_stack_assert sa(ctx); duk_get_global_string(ctx, "\xff""\xff""irccd-ref"); - auto ptr = static_cast<irccd*>(duk_to_pointer(ctx, -1)); + const auto ptr = static_cast<irccd*>(duk_to_pointer(ctx, -1)); duk_pop(ctx); return *ptr;
--- a/libirccd-js/irccd/js/irccd_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/irccd_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -69,9 +69,9 @@ class irccd_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load @@ -80,12 +80,19 @@ }; /** - * Get irccd instance stored in this context. - * - * \param ctx the context - * \return the irccd reference + * \brief Specialize dukx_type_traits for irccd. */ -irccd& dukx_get_irccd(duk_context* ctx); +template <> +class dukx_type_traits<irccd> : public std::true_type { +public: + /** + * Get irccd instance stored in this context. + * + * \param ctx the context + * \return the irccd reference + */ + static irccd& self(duk_context* ctx); +}; } // !irccd
--- a/libirccd-js/irccd/js/js_plugin.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/js_plugin.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -142,7 +142,6 @@ { std::ifstream input(get_path()); - // TODO: add error message here. if (!input) throw plugin_error(plugin_error::exec_error, get_name(), std::strerror(errno)); @@ -267,17 +266,17 @@ { auto self = std::make_unique<js_plugin_loader>(irccd); - self->modules().push_back(std::make_unique<irccd_jsapi>()); - self->modules().push_back(std::make_unique<directory_jsapi>()); - self->modules().push_back(std::make_unique<elapsed_timer_jsapi>()); - self->modules().push_back(std::make_unique<file_jsapi>()); - self->modules().push_back(std::make_unique<logger_jsapi>()); - self->modules().push_back(std::make_unique<plugin_jsapi>()); - self->modules().push_back(std::make_unique<server_jsapi>()); - self->modules().push_back(std::make_unique<system_jsapi>()); - self->modules().push_back(std::make_unique<timer_jsapi>()); - self->modules().push_back(std::make_unique<unicode_jsapi>()); - self->modules().push_back(std::make_unique<util_jsapi>()); + self->get_modules().push_back(std::make_unique<irccd_jsapi>()); + self->get_modules().push_back(std::make_unique<directory_jsapi>()); + self->get_modules().push_back(std::make_unique<elapsed_timer_jsapi>()); + self->get_modules().push_back(std::make_unique<file_jsapi>()); + self->get_modules().push_back(std::make_unique<logger_jsapi>()); + self->get_modules().push_back(std::make_unique<plugin_jsapi>()); + self->get_modules().push_back(std::make_unique<server_jsapi>()); + self->get_modules().push_back(std::make_unique<system_jsapi>()); + self->get_modules().push_back(std::make_unique<timer_jsapi>()); + self->get_modules().push_back(std::make_unique<unicode_jsapi>()); + self->get_modules().push_back(std::make_unique<util_jsapi>()); return self; }
--- a/libirccd-js/irccd/js/js_plugin.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/js_plugin.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -274,7 +274,7 @@ * * \return the modules */ - inline const modules_t& modules() const noexcept + inline const modules_t& get_modules() const noexcept { return modules_; } @@ -284,7 +284,7 @@ * * \return the modules */ - inline modules_t& modules() noexcept + inline modules_t& get_modules() noexcept { return modules_; }
--- a/libirccd-js/irccd/js/jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -59,7 +59,7 @@ * * \return the name */ - virtual std::string name() const = 0; + virtual std::string get_name() const = 0; /** * Load the module into the Javascript plugin.
--- a/libirccd-js/irccd/js/logger_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/logger_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -30,7 +30,9 @@ duk_ret_t print(duk_context* ctx, std::ostream &out) { - out << "plugin " << dukx_get_plugin(ctx)->get_name() << ": " << duk_require_string(ctx, 0) << std::endl; + const auto plugin = dukx_type_traits<js_plugin>::self(ctx); + + out << "plugin " << plugin->get_name() << ": " << duk_require_string(ctx, 0) << std::endl; return 0; } @@ -46,7 +48,7 @@ */ duk_ret_t info(duk_context* ctx) { - return print(ctx, dukx_get_irccd(ctx).get_log().info()); + return print(ctx, dukx_type_traits<irccd>::self(ctx).get_log().info()); } /* @@ -60,7 +62,7 @@ */ duk_ret_t warning(duk_context* ctx) { - return print(ctx, dukx_get_irccd(ctx).get_log().warning()); + return print(ctx, dukx_type_traits<irccd>::self(ctx).get_log().warning()); } /* @@ -74,7 +76,7 @@ */ duk_ret_t debug(duk_context* ctx) { - return print(ctx, dukx_get_irccd(ctx).get_log().debug()); + return print(ctx, dukx_type_traits<irccd>::self(ctx).get_log().debug()); } const duk_function_list_entry functions[] = { @@ -86,7 +88,7 @@ } // !namespace -std::string logger_jsapi::name() const +std::string logger_jsapi::get_name() const { return "Irccd.Logger"; }
--- a/libirccd-js/irccd/js/logger_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/logger_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class logger_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc Module::load
--- a/libirccd-js/irccd/js/plugin_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/plugin_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -46,7 +46,7 @@ std::string name = duk_require_string(ctx, 0); try { - func(dukx_get_irccd(ctx), name); + func(dukx_type_traits<irccd>::self(ctx), name); } catch (const std::out_of_range& ex) { (void)duk_error(ctx, DUK_ERR_REFERENCE_ERROR, "%s", ex.what()); } catch (const std::exception &ex) { @@ -215,9 +215,9 @@ std::shared_ptr<plugin> plugin; if (duk_get_top(ctx) >= 1) - plugin = dukx_get_irccd(ctx).plugins().get(duk_require_string(ctx, 0)); + plugin = dukx_type_traits<irccd>::self(ctx).plugins().get(duk_require_string(ctx, 0)); else - plugin = dukx_get_plugin(ctx); + plugin = dukx_type_traits<js_plugin>::self(ctx); if (!plugin) return 0; @@ -252,7 +252,7 @@ duk_push_array(ctx); - for (const auto& p : dukx_get_irccd(ctx).plugins().list()) { + for (const auto& p : dukx_type_traits<irccd>::self(ctx).plugins().list()) { dukx_push(ctx, p->get_name()); duk_put_prop_index(ctx, -2, i++); } @@ -329,7 +329,7 @@ } // !namespace -std::string plugin_jsapi::name() const +std::string plugin_jsapi::get_name() const { return "Irccd.Plugin"; } @@ -377,7 +377,7 @@ duk_pop(plugin->context()); } -std::shared_ptr<js_plugin> dukx_get_plugin(duk_context* ctx) +std::shared_ptr<js_plugin> dukx_type_traits<js_plugin>::self(duk_context* ctx) { dukx_stack_assert sa(ctx);
--- a/libirccd-js/irccd/js/plugin_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/plugin_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class plugin_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc Module::load @@ -46,12 +46,19 @@ }; /** - * Access the plugin stored in this context. - * - * \param ctx the context - * \return the plugin + * \brief Specialize dukx_type_traits for plugin. */ -std::shared_ptr<js_plugin> dukx_get_plugin(duk_context* ctx); +template <> +class dukx_type_traits<js_plugin> : public std::true_type { +public: + /** + * Access the plugin stored in this context. + * + * \param ctx the context + * \return the plugin + */ + static std::shared_ptr<js_plugin> self(duk_context* ctx); +}; } // !irccd
--- a/libirccd-js/irccd/js/server_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/server_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -372,8 +372,8 @@ duk_check_type(ctx, 0, DUK_TYPE_OBJECT); try { - auto json = duk_json_encode(ctx, 0); - auto s = server_util::from_json(dukx_get_irccd(ctx).get_service(), nlohmann::json::parse(json)); + auto json = nlohmann::json::parse(duk_json_encode(ctx, 0)); + auto s = server_util::from_json(dukx_type_traits<irccd>::self(ctx).get_service(), json); duk_push_this(ctx); duk_push_pointer(ctx, new std::shared_ptr<server>(std::move(s))); @@ -413,7 +413,7 @@ */ duk_ret_t add(duk_context* ctx) { - dukx_get_irccd(ctx).servers().add(dukx_require<std::shared_ptr<server>>(ctx, 0)); + dukx_type_traits<irccd>::self(ctx).servers().add(dukx_require<std::shared_ptr<server>>(ctx, 0)); return 0; } @@ -431,7 +431,7 @@ */ duk_ret_t find(duk_context* ctx) { - auto server = dukx_get_irccd(ctx).servers().get(duk_require_string(ctx, 0)); + auto server = dukx_type_traits<irccd>::self(ctx).servers().get(duk_require_string(ctx, 0)); if (!server) return 0; @@ -454,7 +454,7 @@ { duk_push_object(ctx); - for (const auto &server : dukx_get_irccd(ctx).servers().servers()) { + for (const auto &server : dukx_type_traits<irccd>::self(ctx).servers().servers()) { dukx_push(ctx, server); duk_put_prop_string(ctx, -2, server->get_name().c_str()); } @@ -474,7 +474,7 @@ */ duk_ret_t remove(duk_context* ctx) { - dukx_get_irccd(ctx).servers().remove(duk_require_string(ctx, 0)); + dukx_type_traits<irccd>::self(ctx).servers().remove(duk_require_string(ctx, 0)); return 0; } @@ -509,7 +509,7 @@ } // !namespace -std::string server_jsapi::name() const +std::string server_jsapi::get_name() const { return "Irccd.Server"; }
--- a/libirccd-js/irccd/js/server_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/server_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -37,9 +37,9 @@ class server_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/libirccd-js/irccd/js/system_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/system_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -217,7 +217,7 @@ } // !namespace -std::string system_jsapi::name() const +std::string system_jsapi::get_name() const { return "Irccd.System"; }
--- a/libirccd-js/irccd/js/system_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/system_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class system_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/libirccd-js/irccd/js/timer_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/timer_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -85,10 +85,10 @@ duk_remove(ctx, -2); if (duk_pcall(ctx, 0)) { - dukx_get_irccd(ctx).get_log().warning() << "plugin: " << plugin->get_name() - << " timer error:" << std::endl; - dukx_get_irccd(ctx).get_log().warning() << " " - << dukx_stack(ctx, -1).what() << std::endl; + auto& log = dukx_type_traits<irccd>::self(ctx).get_log(); + + log.warning() << "plugin: " << plugin->get_name() << " timer error:" << std::endl; + log.warning() << " " << dukx_stack(ctx, -1).what() << std::endl; } else duk_pop(ctx); } @@ -189,7 +189,7 @@ duk_del_prop_string(ctx, -1, ptr->key().c_str()); duk_pop(ctx); - dukx_get_irccd(ctx).get_log().debug("timer: destroyed"); + dukx_type_traits<irccd>::self(ctx).get_log().debug("timer: destroyed"); delete ptr; @@ -223,8 +223,9 @@ if (!duk_is_callable(ctx, 2)) duk_error(ctx, DUK_ERR_TYPE_ERROR, "missing callback function"); - auto& daemon = dukx_get_irccd(ctx); - auto object = new timer(daemon.get_service(), dukx_get_plugin(ctx), delay, static_cast<timer::type_t>(type)); + auto plugin = dukx_type_traits<js_plugin>::self(ctx); + auto& daemon = dukx_type_traits<irccd>::self(ctx); + auto object = new timer(daemon.get_service(), plugin, delay, static_cast<timer::type_t>(type)); duk_push_this(ctx); duk_push_pointer(ctx, object); @@ -249,7 +250,7 @@ } // !namespace -std::string timer_jsapi::name() const +std::string timer_jsapi::get_name() const { return "Irccd.Timer"; }
--- a/libirccd-js/irccd/js/timer_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/timer_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class timer_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/libirccd-js/irccd/js/unicode_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/unicode_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -132,7 +132,7 @@ } // !namespace -std::string unicode_jsapi::name() const +std::string unicode_jsapi::get_name() const { return "Irccd.Unicode"; }
--- a/libirccd-js/irccd/js/unicode_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/unicode_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class unicode_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/libirccd-js/irccd/js/util_jsapi.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/util_jsapi.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -277,7 +277,7 @@ } // !namespace -std::string util_jsapi::name() const +std::string util_jsapi::get_name() const { return "Irccd.Util"; }
--- a/libirccd-js/irccd/js/util_jsapi.hpp Tue Mar 27 20:30:59 2018 +0200 +++ b/libirccd-js/irccd/js/util_jsapi.hpp Tue Mar 27 21:01:02 2018 +0200 @@ -35,9 +35,9 @@ class util_jsapi : public jsapi { public: /** - * \copydoc jsapi::name + * \copydoc jsapi::get_name */ - std::string name() const override; + std::string get_name() const override; /** * \copydoc jsapi::load
--- a/tests/src/libirccd-js/js-plugin/main.cpp Tue Mar 27 20:30:59 2018 +0200 +++ b/tests/src/libirccd-js/js-plugin/main.cpp Tue Mar 27 21:01:02 2018 +0200 @@ -107,8 +107,8 @@ auto loader = std::make_unique<js_plugin_loader>(irccd_); - loader->modules().push_back(std::make_unique<irccd_jsapi>()); - loader->modules().push_back(std::make_unique<plugin_jsapi>()); + loader->get_modules().push_back(std::make_unique<irccd_jsapi>()); + loader->get_modules().push_back(std::make_unique<plugin_jsapi>()); irccd_.plugins().add_loader(std::move(loader)); }