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,
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;
}
#define _GNU_SOURCE
#include "ply-hashtable.h"
#include "ply-list.h"
+#include "ply-logger.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include "script.h"
+#include "script-debug.h"
#include "script-execute.h"
#include "script-object.h"
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 *))
{
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;
}
}
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);
}
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 ();
}