]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Generate error messages on erroneous operations
authorCharlie Brej <cbrej@cs.man.ac.uk>
Mon, 31 Aug 2009 00:17:56 +0000 (01:17 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Mon, 31 Aug 2009 00:17:56 +0000 (01:17 +0100)
src/plugins/splash/script/script-debug.c
src/plugins/splash/script/script-execute.c

index 65bc95a995ac7ebc0995a73b5d5648ef713185d0..355c2b2aab60c677a32eaf284e7d869af6f2fd55 100644 (file)
@@ -30,10 +30,12 @@ static ply_hashtable_t *script_debug_name_hash = NULL;
 
 static void script_debug_setup (void)
 {
-  if (script_debug_location_hash) return;
-  script_debug_location_hash = ply_hashtable_new(NULL, NULL);
-  script_debug_name_hash = ply_hashtable_new(ply_hashtable_string_hash,
-                                             ply_hashtable_string_compare);
+  if (!script_debug_location_hash)
+  {
+    script_debug_location_hash = ply_hashtable_new(NULL, NULL);
+    script_debug_name_hash = ply_hashtable_new(ply_hashtable_string_hash,
+                                               ply_hashtable_string_compare);
+  }
 }
 
 void script_debug_add_element (void                    *element,
@@ -63,7 +65,7 @@ void script_debug_remove_element (void *element)
 script_debug_location_t *script_debug_lookup_element (void *element)
 {
   script_debug_setup();
-  script_debug_location_t *location = ply_hashtable_remove (script_debug_location_hash,
+  script_debug_location_t *location = ply_hashtable_lookup (script_debug_location_hash,
                                                             element);
-  return NULL;
+  return location;
 }
index f5e97d5a1a909ede33b4cc3a2c300c3e1c5c349d..66cc678312bc14e35a76f1a8fee6aed0bd051868 100644 (file)
@@ -22,6 +22,7 @@
 #define _GNU_SOURCE
 #include "ply-hashtable.h"
 #include "ply-list.h"
+#include "ply-logger.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -33,6 +34,7 @@
 #include <math.h>
 
 #include "script.h"
+#include "script-debug.h"
 #include "script-execute.h"
 #include "script-object.h"
 
@@ -42,6 +44,22 @@ static script_return_t script_execute_function_with_parlist (script_state_t    *
                                                              script_function_t *function,
                                                              ply_list_t        *parameter_data);
 
+
+static void script_execute_error (void       *element,
+                                  const char *message)
+{
+  script_debug_location_t *location = script_debug_lookup_element (element);
+  if (location)
+    ply_error ("Execution error \"%s\" L:%d C:%d : %s\n",
+               location->name,
+               location->line_index,
+               location->column_index,
+               message);
+  else
+    ply_error ("Execution error: %s\n", message);
+}
+
+
 static script_obj_t *script_evaluate_apply_function (script_state_t *state,
                                                      script_exp_t   *exp,
                                                      script_obj_t   *(*function)(script_obj_t *, script_obj_t *))
@@ -183,7 +201,11 @@ static script_obj_t *script_evaluate_unary (script_state_t *state,
     {
       if (script_obj_is_number(obj))
         new_obj = script_obj_new_number (-script_obj_as_number (obj));
-      else new_obj = script_obj_new_null ();
+      else
+        {
+          script_execute_error(exp, "Cannot negate non number objects");
+          new_obj = script_obj_new_null ();
+        }
       script_obj_unref (obj);
       return new_obj;
     }
@@ -206,6 +228,7 @@ static script_obj_t *script_evaluate_unary (script_state_t *state,
     }
   else
     {
+      script_execute_error(exp, "Cannot increment/decrement non number objects");
       new_obj = script_obj_new_null (); /* If performeing something like a=hash++; a and hash become NULL */
       script_obj_reset (obj);
     }
@@ -222,6 +245,7 @@ static script_obj_t *script_evaluate_func (script_state_t *state,
 
   if (!function)
     {
+      script_execute_error(exp, "Call operated on an object with is not a function");
       script_obj_unref (func_obj);
       return script_obj_new_null ();
     }