Author: cazfi
Date: Fri Feb 26 10:38:57 2016
New Revision: 32092

URL: http://svn.gna.org/viewcvs/freeciv?rev=32092&view=rev
Log:
Added deprecation warnings about deprecated lua signals.

See patch #7007

Modified:
    trunk/common/scriptcore/luascript_signal.c
    trunk/common/scriptcore/luascript_signal.h
    trunk/server/scripting/script_server.c

Modified: trunk/common/scriptcore/luascript_signal.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/luascript_signal.c?rev=32092&r1=32091&r2=32092&view=diff
==============================================================================
--- trunk/common/scriptcore/luascript_signal.c  (original)
+++ trunk/common/scriptcore/luascript_signal.c  Fri Feb 26 10:38:57 2016
@@ -44,6 +44,7 @@
 #include <stdarg.h>
 
 /* utility */
+#include "deprecations.h"
 #include "log.h"
 
 /* common/scriptcore */
@@ -75,6 +76,7 @@
   int nargs;                              /* number of arguments to pass */
   enum api_types *arg_types;              /* argument types */
   struct signal_callback_list *callbacks; /* connected callbacks */
+  char *depr_msg;                         /* deprecation message to show if 
handler added */
 };
 
 /* Signal callback datastructure. */
@@ -137,6 +139,8 @@
   psignal->arg_types = parg_types;
   psignal->callbacks
     = signal_callback_list_new_full(signal_callback_destroy);
+  psignal->depr_msg = NULL;
+
   return psignal;
 }
 
@@ -147,6 +151,9 @@
 {
   if (psignal->arg_types) {
     free(psignal->arg_types);
+  }
+  if (psignal->depr_msg) {
+    free(psignal->depr_msg);
   }
   signal_callback_list_destroy(psignal->callbacks);
   free(psignal);
@@ -203,44 +210,82 @@
 /*****************************************************************************
   Create a new signal type.
 *****************************************************************************/
-void luascript_signal_create_valist(struct fc_lua *fcl,
-                                    const char *signal_name,
-                                    int nargs, va_list args)
+static struct signal *luascript_signal_create_valist(struct fc_lua *fcl,
+                                                     const char *signal_name,
+                                                     int nargs, va_list args)
 {
   struct signal *psignal;
 
-  fc_assert_ret(fcl);
-  fc_assert_ret(fcl->signals);
+  fc_assert_ret_val(fcl, NULL);
+  fc_assert_ret_val(fcl->signals, NULL);
 
   if (luascript_signal_hash_lookup(fcl->signals, signal_name, &psignal)) {
     luascript_log(fcl, LOG_ERROR, "Signal \"%s\" was already created.",
                   signal_name);
+    return NULL;
   } else {
     enum api_types *parg_types = fc_calloc(nargs, sizeof(*parg_types));
     int i;
     char *sn = fc_malloc(strlen(signal_name) + 1);
+    struct signal *created;
 
     for (i = 0; i < nargs; i++) {
       *(parg_types + i) = va_arg(args, int);
     }
+    created = signal_new(nargs, parg_types);
     luascript_signal_hash_insert(fcl->signals, signal_name,
-                                 signal_new(nargs, parg_types));
+                                 created);
     strcpy(sn, signal_name);
     luascript_signal_name_list_append(fcl->signal_names, sn);
+
+    return created;
   }
 }
 
 /*****************************************************************************
   Create a new signal type.
 *****************************************************************************/
-void luascript_signal_create(struct fc_lua *fcl, const char *signal_name,
-                             int nargs, ...)
+signal_deprecator *luascript_signal_create(struct fc_lua *fcl, const char 
*signal_name,
+                                          int nargs, ...)
 {
   va_list args;
+  struct signal *created;
 
   va_start(args, nargs);
-  luascript_signal_create_valist(fcl, signal_name, nargs, args);
+  created = luascript_signal_create_valist(fcl, signal_name, nargs, args);
   va_end(args);
+
+  if (created != NULL) {
+    return &(created->depr_msg);
+  }
+
+  return NULL;
+}
+
+/*****************************************************************************
+  Mark signal deprecated.
+*****************************************************************************/
+void deprecate_signal(signal_deprecator *deprecator, char *signal,
+                      char *replacement, char *deprecated_since)
+{
+  if (deprecator != NULL) {
+    char buffer[1024];
+
+    if (deprecated_since != NULL && replacement != NULL) {
+      fc_snprintf(buffer, sizeof(buffer),
+                  "Deprecated: lua signal \"%s\", deprecated since \"%s\", 
used. "
+                  "Use \"%s\" instead", signal, deprecated_since, replacement);
+    } else if (replacement != NULL) {
+      fc_snprintf(buffer, sizeof(buffer),
+                  "Deprecated: lua signal \"%s\" used. Use \"%s\" instad",
+                  signal, replacement);
+    } else {
+      fc_snprintf(buffer, sizeof(buffer),
+                  "Deprecated: lua signal \"%s\" used.", signal);
+    }
+
+    *deprecator = fc_strdup(buffer);
+  }
 }
 
 /*****************************************************************************
@@ -263,6 +308,10 @@
         break;
       }
     } signal_callback_list_iterate_end;
+
+    if (psignal->depr_msg != NULL) {
+      log_deprecation("%s", psignal->depr_msg);
+    }
 
     if (create) {
       if (pcallback_found) {

Modified: trunk/common/scriptcore/luascript_signal.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/luascript_signal.h?rev=32092&r1=32091&r2=32092&view=diff
==============================================================================
--- trunk/common/scriptcore/luascript_signal.h  (original)
+++ trunk/common/scriptcore/luascript_signal.h  Fri Feb 26 10:38:57 2016
@@ -22,6 +22,8 @@
 
 struct fc_lua;
 
+typedef char * signal_deprecator;
+
 void luascript_signal_init(struct fc_lua *fcl);
 void luascript_signal_free(struct fc_lua *fcl);
 
@@ -29,11 +31,10 @@
                                   int nargs, va_list args);
 void luascript_signal_emit(struct fc_lua *fcl, const char *signal_name,
                            int nargs, ...);
-void luascript_signal_create_valist(struct fc_lua *fcl,
-                                    const char *signal_name, int nargs,
-                                    va_list args);
-void luascript_signal_create(struct fc_lua *fcl, const char *signal_name,
-                             int nargs, ...);
+signal_deprecator *luascript_signal_create(struct fc_lua *fcl, const char 
*signal_name,
+                                           int nargs, ...);
+void deprecate_signal(signal_deprecator *deprecator, char *signal,
+                      char *replacement, char *deprecated_since);
 void luascript_signal_callback(struct fc_lua *fcl, const char *signal_name,
                                const char *callback_name, bool create);
 bool luascript_signal_callback_defined(struct fc_lua *fcl,

Modified: trunk/server/scripting/script_server.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/script_server.c?rev=32092&r1=32091&r2=32092&view=diff
==============================================================================
--- trunk/server/scripting/script_server.c      (original)
+++ trunk/server/scripting/script_server.c      Fri Feb 26 10:38:57 2016
@@ -70,7 +70,7 @@
 static void script_server_code_load(struct section_file *file);
 static void script_server_code_save(struct section_file *file);
 
-static void script_server_signal_create(void);
+static void script_server_signals_create(void);
 static void script_server_functions_define(void);
 
 static void script_server_cmd_reply(struct fc_lua *fcl, enum log_level level,
@@ -283,7 +283,7 @@
   script_server_vars_init();
 
   luascript_signal_init(fcl_main);
-  script_server_signal_create();
+  script_server_signals_create();
 
   luascript_func_init(fcl_main);
   script_server_functions_define();
@@ -342,15 +342,18 @@
 /*****************************************************************************
   Declare any new signal types you need here.
 *****************************************************************************/
-static void script_server_signal_create(void)
-{
+static void script_server_signals_create(void)
+{
+  signal_deprecator *depr;
+
   luascript_signal_create(fcl_main, "turn_begin", 2,
                           API_TYPE_INT, API_TYPE_INT);
 
   /* Deprecated form of the 'turn_begin' signal that counts real turns
    * starting from 0. */
-  luascript_signal_create(fcl_main, "turn_started", 2,
-                          API_TYPE_INT, API_TYPE_INT);
+  depr = luascript_signal_create(fcl_main, "turn_started", 2,
+                                 API_TYPE_INT, API_TYPE_INT);
+  deprecate_signal(depr, "turn_started", "turn_begin", "3.0");
 
   luascript_signal_create(fcl_main, "unit_moved", 3,
                           API_TYPE_UNIT, API_TYPE_TILE, API_TYPE_TILE);
@@ -363,8 +366,9 @@
                           API_TYPE_CITY, API_TYPE_INT, API_TYPE_STRING);
 
   /* Deprecated form of the 'city_size_change' signal for the case of growth. 
*/
-  luascript_signal_create(fcl_main, "city_growth", 2,
-                          API_TYPE_CITY, API_TYPE_INT);
+  depr = luascript_signal_create(fcl_main, "city_growth", 2,
+                                 API_TYPE_CITY, API_TYPE_INT);
+  deprecate_signal(depr, "city_growth", "city_size_change", "2.6");
 
   /* Only includes units built in cities, for now. */
   luascript_signal_create(fcl_main, "unit_built", 2,
@@ -400,8 +404,9 @@
 
   /* Deprecated form of the 'city_transferred' signal for the case of
    * conquest. */
-  luascript_signal_create(fcl_main, "city_lost", 3,
-                          API_TYPE_CITY, API_TYPE_PLAYER, API_TYPE_PLAYER);
+  depr = luascript_signal_create(fcl_main, "city_lost", 3,
+                                 API_TYPE_CITY, API_TYPE_PLAYER, 
API_TYPE_PLAYER);
+  deprecate_signal(depr, "city_lost", "city_transferred", "2.6");
 
   luascript_signal_create(fcl_main, "hut_enter", 1,
                           API_TYPE_UNIT);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to