void set_error_string( FeriteScript *script,  FeriteObject *object, char* str ) {
	FeriteVariable *estr;
	estr = ferite_hash_get(script, object->variables->variables, "_errstr");
 	if( estr == NULL )
 		return;
	ferite_str_set( script, VAS(estr), str, 0,  FE_CHARSET_DEFAULT );
}
Ejemplo n.º 2
0
/**
 * @function ferite_raise_script_error
 * @declaration void ferite_raise_script_error( FeriteScript *script, int err, char *fmt, ... )
 * @brief Raise an exception within the ferite engine.
 * @param FeriteScript *script The running script
 * @param int err	The error code
 * @param char *fmt	The format of the error string
 * @description Use the same formating codes as printf with this function
 */
void ferite_raise_script_error( FeriteScript *script, int err, char *fmt, ... )
{
	FeriteNamespaceBucket *nsb = NULL;
	FeriteVariable *global_error_object = NULL, *new_error_object = NULL, *backtrace = NULL;
	FeriteVariable *error_object_str = NULL, *error_object_num = NULL, *error_object_backtrace = NULL;
	FeriteBuffer *error_buffer = NULL;
	char *msg;
	va_list ap;

	FE_ENTER_FUNCTION;
	va_start( ap, fmt );

	error_buffer = ferite_buffer_new(script, 0);
	ferite_buffer_vprintf( script, error_buffer, fmt, &ap );
	msg = ferite_buffer_get( script, script->error, NULL );
	
	FUD(("ERROR RAISED: %s %d\n", msg, err ));

	nsb = ferite_namespace_element_exists( script, script->mainns, "err" );
	FE_ASSERT( nsb && nsb->type == FENS_VAR );
	global_error_object = nsb->data;
	script->error_state = FE_ERROR_THROWN;

	if( VAO(global_error_object) == NULL )
	{
		nsb = ferite_namespace_element_exists( script, script->mainns, "Error" );
		if( nsb == NULL )
		{
			FE_LEAVE_FUNCTION( NOWT );
			exit(1);
		}
		new_error_object = ferite_new_object( script, nsb->data, NULL );
		VAO(global_error_object) = VAO(new_error_object);
		FINCREF(VAO(global_error_object));
		ferite_variable_destroy( script, new_error_object );
	}

	error_object_str = ferite_object_get_var( script, VAO(global_error_object), "str" );
	ferite_str_set( script, VAS(error_object_str), msg, strlen(msg), FE_CHARSET_DEFAULT );
	ffree( msg );

	error_object_num = ferite_object_get_var( script, VAO(global_error_object), "num" );
	VAI(error_object_num) = err;
	
	backtrace = ferite_generate_backtrace( script, FE_FALSE );
	error_object_backtrace = ferite_object_get_var( script, VAO(global_error_object), "backtrace");
	ferite_variable_fast_assign( script, error_object_backtrace, backtrace );
	
	ferite_buffer_delete( script, error_buffer );
	
	FE_LEAVE_FUNCTION( NOWT );
}
Ejemplo n.º 3
0
/**
 * @function ferite_set_error
 * @declaration void ferite_set_error( FeriteScript *script, int num, char *fmt, ... )
 * @brief Same as ferite_error except this wont raise an exception at runtime
 */
void ferite_set_error( FeriteScript *script, int num, char *fmt, ... )
{
	FeriteNamespaceBucket *nsb = NULL;
	FeriteVariable *global_error_object = NULL, *new_error_object = NULL;
	FeriteVariable *errstr = NULL, *erno = NULL;
	va_list ap;
	char *buf = NULL;

	FE_ENTER_FUNCTION;

	if( !script->is_being_deleted && (script->parent == NULL || !script->parent->is_being_deleted) )
	{
		buf = fmalloc( 4096 );
		va_start( ap, fmt );
		vsprintf( buf, fmt, ap );

		nsb = ferite_namespace_element_exists( script, script->mainns, "err" );
		FE_ASSERT( nsb && nsb->type == FENS_VAR );
		global_error_object = nsb->data;

		if( VAO(global_error_object) == NULL )
		{
			nsb = ferite_namespace_element_exists( script, script->mainns, "Error" );
			new_error_object = ferite_new_object( script, nsb->data, NULL );
			VAO(global_error_object) = VAO(new_error_object);
			FINCREF(VAO(global_error_object));
			ferite_variable_destroy( script, new_error_object );
		}

		errstr = ferite_object_get_var( script, VAO(global_error_object), "str" );
		ferite_str_set( script, VAS(errstr), buf, strlen(buf), FE_CHARSET_DEFAULT );

		erno = ferite_object_get_var( script, VAO(global_error_object), "num" );
		VAI(erno) = num;

		ffree( buf );
		va_end( ap );
	}
	FE_LEAVE_FUNCTION( NOWT );
}