changeset 213:68831a43b1ab

Irccd: move the config and format property names in JsPlugin
author David Demelier <markand@malikania.fr>
date Thu, 23 Jun 2016 12:49:59 +0200
parents b224b85a6ebf
children bf4b72fee6c2
files lib/irccd/mod-plugin.cpp lib/irccd/mod-plugin.hpp lib/irccd/plugin-js.cpp lib/irccd/plugin-js.hpp
diffstat 4 files changed, 48 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/lib/irccd/mod-plugin.cpp	Thu Jun 23 07:35:41 2016 +0200
+++ b/lib/irccd/mod-plugin.cpp	Thu Jun 23 12:49:59 2016 +0200
@@ -127,7 +127,7 @@
  */
 duk_ret_t setConfig(duk_context *ctx)
 {
-    return set(ctx, PluginConfigProperty);
+    return set(ctx, JsPlugin::ConfigProperty);
 }
 
 /*
@@ -138,7 +138,7 @@
  */
 duk_ret_t getConfig(duk_context *ctx)
 {
-    return get(ctx, PluginConfigProperty);
+    return get(ctx, JsPlugin::ConfigProperty);
 }
 
 /*
@@ -149,7 +149,7 @@
  */
 duk_ret_t setFormat(duk_context *ctx)
 {
-    return set(ctx, PluginFormatProperty);
+    return set(ctx, JsPlugin::FormatProperty);
 }
 
 /*
@@ -160,7 +160,7 @@
  */
 duk_ret_t getFormat(duk_context *ctx)
 {
-    return get(ctx, PluginFormatProperty);
+    return get(ctx, JsPlugin::FormatProperty);
 }
 
 /*
--- a/lib/irccd/mod-plugin.hpp	Thu Jun 23 07:35:41 2016 +0200
+++ b/lib/irccd/mod-plugin.hpp	Thu Jun 23 12:49:59 2016 +0200
@@ -30,16 +30,6 @@
 namespace irccd {
 
 /**
- * Global property where to read/write plugin configuration.
- */
-const char PluginConfigProperty[] = "\xff""\xff""irccd-plugin-config";
-
-/**
- * Global property where to read/write plugin formats.
- */
-const char PluginFormatProperty[] = "\xff""\xff""irccd-plugin-format";
-
-/**
  * \brief Irccd.Plugin JavaScript API.
  * \ingroup modules
  */
--- a/lib/irccd/plugin-js.cpp	Thu Jun 23 07:35:41 2016 +0200
+++ b/lib/irccd/plugin-js.cpp	Thu Jun 23 12:49:59 2016 +0200
@@ -36,6 +36,9 @@
 
 namespace irccd {
 
+const char JsPlugin::ConfigProperty[] = "\xff""\xff""irccd-plugin-config";
+const char JsPlugin::FormatProperty[] = "\xff""\xff""irccd-plugin-format";
+
 std::unordered_map<std::string, std::string> JsPlugin::getTable(const char *name) const
 {
     StackAssert sa(m_context);
@@ -142,29 +145,9 @@
      * In mod-plugin.cpp.
      */
     duk_push_object(m_context);
-    duk_put_global_string(m_context, PluginConfigProperty);
+    duk_put_global_string(m_context, ConfigProperty);
     duk_push_object(m_context);
-    duk_put_global_string(m_context, PluginFormatProperty);
-}
-
-PluginConfig JsPlugin::config()
-{
-    return getTable(PluginConfigProperty);
-}
-
-void JsPlugin::setConfig(PluginConfig config)
-{
-    putTable(PluginConfigProperty, config);
-}
-
-PluginFormats JsPlugin::formats()
-{
-    return getTable(PluginFormatProperty);
-}
-
-void JsPlugin::setFormats(PluginFormats formats)
-{
-    putTable(PluginFormatProperty, formats);
+    duk_put_global_string(m_context, FormatProperty);
 }
 
 void JsPlugin::onChannelMode(Irccd &, const ChannelModeEvent &event)
--- a/lib/irccd/plugin-js.hpp	Thu Jun 23 07:35:41 2016 +0200
+++ b/lib/irccd/plugin-js.hpp	Thu Jun 23 12:49:59 2016 +0200
@@ -38,6 +38,17 @@
  * \ingroup plugins
  */
 class JsPlugin : public Plugin {
+public:
+    /**
+     * Global property where to read/write plugin configuration (object).
+     */
+    static const char ConfigProperty[];
+
+    /**
+     * Global property where to read/write plugin formats (object).
+     */
+    static const char FormatProperty[];
+
 private:
     // JavaScript context
     UniqueContext m_context;
@@ -72,13 +83,37 @@
         return m_context;
     }
 
-    IRCCD_EXPORT PluginConfig config() override;
+    /**
+     * \copydoc Plugin::config
+     */
+    PluginConfig config() override
+    {
+        return getTable(ConfigProperty);
+    }
 
-    IRCCD_EXPORT void setConfig(PluginConfig) override;
+    /**
+     * \copydoc Plugin::setConfig
+     */
+    void setConfig(PluginConfig config) override
+    {
+        putTable(ConfigProperty, config);
+    }
 
-    IRCCD_EXPORT PluginFormats formats() override;
+    /**
+     * \copydoc Plugin::formats
+     */
+    PluginFormats formats() override
+    {
+        return getTable(FormatProperty);
+    }
 
-    IRCCD_EXPORT void setFormats(PluginFormats formats) override;
+    /**
+     * \copydoc Plugin::setConfig
+     */
+    void setFormats(PluginFormats formats) override
+    {
+        putTable(FormatProperty, formats);
+    }
 
     /**
      * \copydoc Plugin::onCommand