From: Charlie Brej Date: Mon, 31 Aug 2009 00:17:56 +0000 (+0100) Subject: [script] Generate error messages on erroneous operations X-Git-Tag: 0.7.2~24^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4539abfba2d69643a16ba00dd45d146d6035b787;p=thirdparty%2Fplymouth.git [script] Generate error messages on erroneous operations --- diff --git a/src/plugins/splash/script/script-debug.c b/src/plugins/splash/script/script-debug.c index 65bc95a9..355c2b2a 100644 --- a/src/plugins/splash/script/script-debug.c +++ b/src/plugins/splash/script/script-debug.c @@ -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; } diff --git a/src/plugins/splash/script/script-execute.c b/src/plugins/splash/script/script-execute.c index f5e97d5a..66cc6783 100644 --- a/src/plugins/splash/script/script-execute.c +++ b/src/plugins/splash/script/script-execute.c @@ -22,6 +22,7 @@ #define _GNU_SOURCE #include "ply-hashtable.h" #include "ply-list.h" +#include "ply-logger.h" #include #include #include @@ -33,6 +34,7 @@ #include #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 (); }