/**
* @function ferite_find_namespace_element_contents
 * @declaration void *ferite_find_namespace_element_contents( FeriteScript *script, FeriteNamespace *parent, char *obj, int type )
 * @brief Recusively look in a namespace for an element and it's contents
 * @param FeriteScript *script The script
 * @param FeriteNamespace *parent The namespace to look in
 * @param char *obj The name to locate
 * @param int type The type to look for
 * @return The contents of the namespace bucket if it is found otherwise NULL
 * @description The type dictates what is returned. No type is specified (0) then if any element is
 *              found then it will be returned. If a type is specified then it is checked to see if
 *              the bucket is of the correct type, if so it is returned, if not NULL is returned.<nl/>
 *              <nl/>
 *              The types are FENS_VAR, FENS_FNC, FENS_CLS, or FENS_NS.
 */
void *ferite_find_namespace_element_contents( FeriteScript *script, FeriteNamespace *parent, char *obj, int type )
{
    FeriteNamespaceBucket *nsb = ferite_find_namespace( script, parent, obj, type );
    if( nsb != NULL )
        return nsb->data;
    return NULL;
}
Exemplo n.º 2
0
/**
 * @function ferite_init_error_system
 * @declaration void ferite_init_error_system( FeriteScript *script, FeriteNamespace *ns )
 * @brief Setup the special error handling class on a script
 * @param FeriteScript *script The current script
 * @param FeriteNamespace *ns	 The namespace in which the class should be registered
 */
void ferite_init_error_system( FeriteScript *script, FeriteNamespace *ns )
{
	FeriteClass *ferite_error_class = NULL;
	FeriteVariable *var, *errobj = NULL;
	FeriteNamespaceBucket *nsb = NULL;
	
	FE_ENTER_FUNCTION;
	ferite_error_class = ferite_register_class( script, ns, "Error" );
	ferite_register_class_variable( script, ferite_error_class, "num", ferite_create_number_long_variable( script, "num", 0, FE_STATIC ), 0 );
	ferite_register_class_variable( script, ferite_error_class, "str", ferite_create_string_variable( script, "str", NULL, FE_STATIC ), 0 );
	ferite_register_class_variable( script, ferite_error_class, "backtrace", ferite_create_uarray_variable( script, "backtrace", 32, FE_STATIC ), 0 );

	fe_create_cls_fnc( script, ferite_error_class, "constructor", ferite_error_constructor_sn, "sn", FE_FALSE );
	fe_create_cls_fnc( script, ferite_error_class, "constructor", ferite_error_constructor_s, "s", FE_FALSE );
	fe_create_cls_fnc( script, ferite_error_class, "backtrace", ferite_error_backtrace, "", FE_FALSE );
	
	nsb = ferite_find_namespace( script, script->mainns, "err", FENS_VAR );
	if( nsb != NULL ) {
		errobj = ferite_build_object( script, ferite_error_class );
		var = nsb->data;
		VAO(var) = VAO(errobj);
		VAO(errobj) = NULL;
		ferite_variable_destroy( script, errobj );
	}
	
	FE_LEAVE_FUNCTION(NOWT);
}
FeriteVariable *create_ferite_header_object( FeriteScript *script, ENVELOPE *env )
{
    FeriteVariable *header = NULL, *v = NULL;
    FeriteNamespaceBucket *nsb = NULL;
    #define BUFSIZE 1025
    char buf[BUFSIZE];
    int i = 0;

    if( env == NULL)
      return NULL;

    ADDRESS *address_source[6] = { env->from, env->reply_to, env->cc, env->bcc, env->sender, env->to };
    char *address_target[6] = { "from", "reply_to" , "cc", "bcc", "sender" , "to" };
    int n_address_source = 6;

    char *source[5] = { env->subject, env->date, env->message_id, env->in_reply_to, env->references };
    char *target[5] = { "subject", "date", "ID", "in_reply_to", "references" };
    int  n_source = 5;

    nsb = ferite_find_namespace( script, script->mainns, "Mail.MessageHeader", FENS_CLS );
    if( nsb == NULL)
	    return NULL;

    header = ferite_build_object( script, (FeriteClass *)nsb->data );
    if( header == NULL )
	    return NULL;


    //Parse each address structure in address_source[] and write the result to the
    //corresonding object member in address_target[]
    for(i=0; i < n_address_source; i++) {
	    v = create_address_list( script, address_source[i] );
	    if( v == NULL ) {
		    //set_error_string( script, self, "Couldn't create address list" );
		    return NULL;
	    }
	    ferite_object_set_var(script, VAO(header), address_target[i], v );
    }

    //Copy  each header-field in source[] to the
    //corresonding object member in address_target[]
    for(i=0; i< n_source; i++) {
	    if( source[i] ) {
		    v = fe_new_str(target[i], source[i] , 0, FE_CHARSET_DEFAULT );
		    if( v == NULL ) {
			    //set_error_string( script, self, "Couldn't create mail header" );
			    return NULL;
		    }
		    ferite_object_set_var(script, VAO(header), target[i], v );
		    if( debug_cmail_module && strcmp( target[i], "subject" ) == 0 ) {
				output_printf(OUTPUT_DEBUG,"module.mail: Processing email with subject: '%s'", source[i] );
		    }
	    }
    }
    return header;
}
FeriteVariable *create_address_list(FeriteScript *script, ADDRESS *root) {
    FeriteNamespaceBucket *nsb;
	FeriteVariable *address_list, *item_list, *item;
	ADDRESS *curr;
	int error;

	nsb = ferite_find_namespace( script, script->mainns, "Mail.AddressList", FENS_CLS );
	if( nsb == NULL )
		return NULL;
	address_list = ferite_build_object( script, (FeriteClass *)nsb->data );
	if( address_list == NULL )
		return NULL;

	//Get the array (member of address_list) and populate it with
	//the entries in the linked list current
	item_list = ferite_hash_get( script, VAO(address_list)->variables->variables, "list" );

	nsb = ferite_find_namespace( script, script->mainns, "Mail.Address", FENS_CLS );
	if( nsb == NULL ) {
		return NULL;
	}

	curr=root;
	while( curr ) {
		item =  ferite_build_object( script, (FeriteClass *)nsb->data );
		if( item == NULL )
			return NULL;
		error = create_address( script, item, curr);
		if(error) {
			return NULL;
		}
		ferite_uarray_add( script, VAUA(item_list), item, NULL , FE_ARRAY_ADD_AT_END);
		curr = curr->next;
	}
	return address_list;
}
Exemplo n.º 5
0
void ferite_string_init( FeriteScript *script )
{
	FeriteNamespaceBucket *nsb = ferite_find_namespace(script, script->mainns, "String", FENS_NS);
	FeriteNamespace *string_namespace = (nsb && nsb->data ? nsb->data : ferite_register_namespace(script, "String", script->mainns));
	/* FeriteNamespace *array_namespace = (nsb->data ? nsb->data : ferite_register_namespace(script, "String", script->mainns)); */
	FeriteFunction *length_function = ferite_create_external_function(script, "length", ferite_string_length, "s");
	FeriteFunction *byte_to_number_function = ferite_create_external_function(script, "byteToNumber", ferite_string_byte_to_number, "s");
	FeriteFunction *number_to_byte_function = ferite_create_external_function(script, "numberToByte", ferite_string_number_to_byte, "n");
	FeriteFunction *to_number_function = ferite_create_external_function(script, "toNumber", ferite_string_to_number, "s");
	FeriteFunction *to_lower_function = ferite_create_external_function(script, "toLower", ferite_string_to_lower, "s");
	ferite_register_ns_function(script, string_namespace, length_function);
	ferite_register_ns_function(script, string_namespace, byte_to_number_function);
	ferite_register_ns_function(script, string_namespace, number_to_byte_function);
	ferite_register_ns_function(script, string_namespace, to_number_function);
	ferite_register_ns_function(script, string_namespace, to_lower_function);
}
FeriteVariable *create_ferite_mail_object( FeriteScript *script, FeriteVariable *header, FeriteVariable *content )
{
    FeriteVariable *mailobject;
    FeriteNamespaceBucket *nsb;

    nsb = ferite_find_namespace( script, script->mainns, "Mail.Message", FENS_CLS );
    if( nsb == NULL )
	    return NULL;
    mailobject = ferite_build_object( script, (FeriteClass *)nsb->data );
    if( mailobject == NULL )
	    return NULL;
	if( header )
	    ferite_object_set_var(script, VAO(mailobject), "header", header );
	if( content )
	    ferite_object_set_var(script, VAO(mailobject), "content", content );
    return mailobject;
}
/**
 * @function ferite_find_namespace
 * @declaration FeriteNamespaceBucket *ferite_find_namespace( FeriteScript *script, FeriteNamespace *parent, char *obj, int type )
 * @brief Recusively look in a namespace for an element
 * @param FeriteScript *script The script
 * @param FeriteNamespace *parent The namespace to look in
 * @param char *obj The name to locate
 * @param int type The type to look for
 * @return The namespace bucket if it is found otherwise NULL
 * @description The type dictates what is returned. No type is specified (0) then if any element is
 *              found then it will be returned. If a type is specified then it is checked to see if
 *              the bucket is of the correct type, if so it is returned, if not NULL is returned.<nl/>
 *              <nl/>
 *              The types are FENS_VAR, FENS_FNC, FENS_CLS, or FENS_NS.
 */
FeriteNamespaceBucket *ferite_find_namespace( FeriteScript *script, FeriteNamespace *parent, char *obj, int type )
{
    FeriteNamespaceBucket *nsb = NULL;
    char *buf;
    int i = 0;

    FE_ENTER_FUNCTION;
    FE_ASSERT( parent != NULL && obj != NULL );

    if( ferite_find_string( obj, "." ) == -1 )
    { 
        /* we need not split the string up */
        nsb = ferite_namespace_element_exists( script, parent, obj );
        if( type > 0 )
        {
            if( nsb == NULL || nsb->type != type )
            {
                FE_LEAVE_FUNCTION( NULL );
            }
        }
        FE_LEAVE_FUNCTION( nsb );
    }
    else
    { 
        /* we need to split the string up */
        buf = memset( fmalloc( strlen(obj)+1 ), '\0', strlen(obj) );
        for( i = 0; obj[i] != '.'; i++ );
        strncpy( buf, obj, i );
        nsb = ferite_namespace_element_exists( script, parent, buf );
        ffree( buf );
        if( nsb == NULL || nsb->type != FENS_NS )
        {
            FE_LEAVE_FUNCTION( NULL );
        }
        if( type == FENS_PARENT_NS && ferite_find_string( obj+i+1, "." ) == -1 )
        {
            FE_LEAVE_FUNCTION( nsb );
        }
        FE_LEAVE_FUNCTION( ferite_find_namespace( script, nsb->data, obj+i+1, type ) );
    }
    FE_LEAVE_FUNCTION( NULL );
}
Exemplo n.º 8
0
void game_engine_network_init( FeriteScript *script )
{
	FeriteNamespaceBucket *nsb = ferite_find_namespace(script, script->mainns, "Network", FENS_NS);
	FeriteNamespace *network_namespace = (nsb && nsb->data ? nsb->data : ferite_register_namespace(script, "Network", script->mainns));
	
	FeriteClass *server_class = ferite_register_inherited_class(script, network_namespace, "Server", NULL);
	FeriteClass *client_class = ferite_register_inherited_class(script, network_namespace, "Client", NULL);
	
	ferite_register_ns_variable(script, network_namespace, "MESSAGE_DATA", ferite_create_number_long_variable(script, "MESSAGE_DATA", ENET_EVENT_TYPE_RECEIVE, FE_STATIC));
	ferite_register_ns_variable(script, network_namespace, "MESSAGE_CONNECT", ferite_create_number_long_variable(script, "MESSAGE_CONNECT", ENET_EVENT_TYPE_CONNECT, FE_STATIC));
	ferite_register_ns_variable(script, network_namespace, "MESSAGE_DISCONNECT", ferite_create_number_long_variable(script, "MESSAGE_DISCONNECT", ENET_EVENT_TYPE_DISCONNECT, FE_STATIC));

	ferite_register_inherited_class(script, network_namespace, "Peer", NULL);
	
	ferite_register_inherited_class(script, network_namespace, "ConnectMessage", NULL);
	ferite_register_inherited_class(script, network_namespace, "DisconnectMessage", NULL);
	ferite_register_inherited_class(script, network_namespace, "DataMessage", NULL);
	
	FeriteFunction *server_start_function = ferite_create_external_function(script, "start", game_engine_network_server_start, "n");
	FeriteFunction *server_destroy_function = ferite_create_external_function(script, "destroy", game_engine_network_server_destroy, "");
	FeriteFunction *server_flush_function = ferite_create_external_function(script, "flush", game_engine_network_server_flush, "");
	FeriteFunction *server_service_function = ferite_create_external_function(script, "service", game_engine_network_server_service, "n");
	FeriteFunction *server_send_function = ferite_create_external_function(script, "send", game_engine_network_server_send, "os");
	
	ferite_register_class_function(script, server_class, server_start_function, FE_TRUE);
	ferite_register_class_function(script, server_class, server_destroy_function, FE_FALSE);
	ferite_register_class_function(script, server_class, server_flush_function, FE_FALSE);
	ferite_register_class_function(script, server_class, server_service_function, FE_FALSE);
	ferite_register_class_function(script, server_class, server_send_function, FE_FALSE);
	
	FeriteFunction *client_start_function = ferite_create_external_function(script, "start", game_engine_network_client_start, "sn");
	FeriteFunction *client_destroy_function = ferite_create_external_function(script, "destroy", game_engine_network_client_destroy, "");
	FeriteFunction *client_flush_function = ferite_create_external_function(script, "flush", game_engine_network_client_flush, "");
	FeriteFunction *client_service_function = ferite_create_external_function(script, "service", game_engine_network_client_service, "n");
	FeriteFunction *client_send_function = ferite_create_external_function(script, "send", game_engine_network_client_send, "s");
	
	ferite_register_class_function(script, client_class, client_start_function, FE_TRUE);
	ferite_register_class_function(script, client_class, client_destroy_function, FE_FALSE);
	ferite_register_class_function(script, client_class, client_flush_function, FE_FALSE);
	ferite_register_class_function(script, client_class, client_service_function, FE_FALSE);
	ferite_register_class_function(script, client_class, client_send_function, FE_FALSE);
}
Exemplo n.º 9
0
void ferite_array_init( FeriteScript *script )
{
	FeriteNamespaceBucket *nsb = ferite_find_namespace(script, script->mainns, "Array", FENS_NS);
	FeriteNamespace *array_namespace = (nsb && nsb->data ? nsb->data : ferite_register_namespace(script, "Array", script->mainns));
	/* FeriteNamespace *array_namespace = (nsb->data ? nsb->data : ferite_register_namespace(script, "Array", script->mainns)); */
	FeriteFunction *size_function = ferite_create_external_function(script, "size", ferite_array_size, "a");
	FeriteFunction *key_exists_function = ferite_create_external_function(script, "keyExists", ferite_array_key_exists, "as");
	FeriteFunction *delete_at_function = ferite_create_external_function(script, "deleteAt", ferite_array_delete_at, "an");
	/*FeriteFunction *push_function = ferite_create_external_function(script, "push", ferite_array_push, "av");
	FeriteFunction *pop_function = ferite_create_external_function(script, "pop", ferite_array_pop, "a");
	FeriteFunction *unshift_function = ferite_create_external_function(script, "unshift", ferite_array_unshift, "as");
	FeriteFunction *shift_function = ferite_create_external_function(script, "shift", ferite_array_shift, "a");*/
	ferite_register_ns_function(script, array_namespace, size_function);
	ferite_register_ns_function(script, array_namespace, key_exists_function);
	ferite_register_ns_function(script, array_namespace, delete_at_function);
	/*ferite_register_ns_function(script, array_namespace, pop_function);
	ferite_register_ns_function(script, array_namespace, push_function);
	ferite_register_ns_function(script, array_namespace, unshift_function);
	ferite_register_ns_function(script, array_namespace, shift_function);*/
}
Exemplo n.º 10
0
FeriteVariable *create_ferite_content_object( FeriteScript *script, MAILSTREAM *stream, BODY *body, int msgno, char *sec )
{
	if( body != NULL ) {
		FeriteVariable *object = NULL,*v = NULL;
		FeriteNamespaceBucket *nsb = NULL;
		char *object_name = NULL;

		object_name = ( body->type == TYPEMULTIPART ) ? "Mail.MessageMultiPart" : "Mail.MessagePart" ;

		nsb = ferite_find_namespace( script, script->mainns, object_name , FENS_CLS );
		if( nsb == NULL )
			return NULL;
		object = ferite_build_object( script, (FeriteClass *)nsb->data );
		if( object == NULL )
			return NULL;

		v  = fe_new_lng("type",body->type);
		ferite_object_set_var(script, VAO(object), "type", v);
		output_printf(OUTPUT_DEBUG,"module.mail: setting type %d", body->type);
		if( body->subtype ) {
			v = fe_new_str( "subtype", body->subtype, 0, FE_CHARSET_DEFAULT );
			ferite_object_set_var( script, VAO(object), "subtype", v );
		}

		if( body->type == TYPEMULTIPART ) {
			PART *part = NULL;
			int i = 0;
			char sec2[200];
			FeriteVariable *ret = NULL, *parts = NULL;

			parts = ferite_hash_get(script,VAO(object)->variables->variables,"parts");
			part = body->nested.part;
			while( part ) {
				i++;
				if( sec ) {
					snprintf(sec2,200,"%s.%d",sec,i);
				} else {
					snprintf(sec2,200,"%d",i);
				}
				ret = create_ferite_content_object( script, stream, &part->body, msgno, sec2 );
				ferite_uarray_add( script, VAUA(parts), ret , NULL, FE_ARRAY_ADD_AT_END );
				part = part->next;
			}
			v = fe_new_lng("nparts", i);
			ferite_object_set_var(script, VAO(object), "nparts", v );
		}
		else
		{
			long len = 0,len2 = 0;
			unsigned char *buf = NULL, *buf2 = NULL;
			SIZEDTEXT src, dest;
			FeriteVariable *v = NULL;
			PARAMETER *param = NULL;
			int i = 0;

			if( sec == NULL )
				sec = "1";
			buf = mail_fetchbody( stream, msgno, sec, &len );

			switch(body->encoding){
				case ENCQUOTEDPRINTABLE:
					if( debug_cmail_module )
						output_printf(OUTPUT_DEBUG,"module.mail: Decoding from encoded quotable");
					buf2 = rfc822_qprint(buf,len,&len2);
					break;
				case ENCBASE64: 
					if( debug_cmail_module )
						output_printf(OUTPUT_DEBUG,"module.mail: Decoding from base64");
					buf2=rfc822_base64(buf,len,&len2);
					break;
				default: 
					buf2=buf;
					len2=len;
			}

			if( debug_cmail_module ) {
				output_printf(OUTPUT_DEBUG,"module.mail: id: %s, description: %s", body->id, body->description);
				output_printf(OUTPUT_DEBUG,"module.mail: block type: %d.%s", body->type, body->subtype);
			}
			if( body->parameter ) /* Try and get the content type correctly */ {
				PARAMETER *ptr = body->parameter;
				while( ptr != NULL ) {
					if( caseless_compare( ptr->attribute, "charset" ) ) {
						if( debug_cmail_module )
							output_printf(OUTPUT_DEBUG,"module.mail: Found content type for block: %s", ptr->value);
						v = fe_new_str("charset", ptr->value, 0, FE_CHARSET_DEFAULT);
						ferite_object_set_var(script, VAO(object), "charset", v);
					}
					ptr = ptr->next;
				}
			}
			v = fe_new_bin_str("content", buf2, len2, FE_CHARSET_DEFAULT );
			ferite_object_set_var(script, VAO(object), "content", v );

			v = fe_new_lng("encoding", body->encoding );
			ferite_object_set_var(script, VAO(object), "encoding", v );

			if( body->id ) {
				v = fe_new_str("ID", body->id, strlen(body->id), FE_CHARSET_DEFAULT);
				ferite_object_set_var(script, VAO(object), "ID", v);
			}
			
			if( body->disposition.type && strcasecmp(body->disposition.type, "attachment") == 0) {
				param = body->disposition.parameter;
				while(param){
					if( param->attribute && ((strcasecmp(param->attribute,"filename") == 0) ||
												(strcasecmp(param->attribute,"name") == 0) ||
												(strcasecmp(param->attribute,"name*") == 0) ||
												(strcasecmp(param->attribute,"filename*") == 0) )) {
						v = fe_new_str("filename", param->value, 0, FE_CHARSET_DEFAULT );
						ferite_object_set_var(script, VAO(object), "filename", v );
						break;
					}
					param=param->next;
				}
			}
			/* If filename was not found in Content-Disposition header search for it among the parameters */
			if( strcmp(VAS(ferite_object_get_var(script, VAO(object), "filename"))->data, "") == 0 ) {
				param = body->parameter;
				while(param){
					if( param->attribute && ((strcasecmp(param->attribute,"filename") == 0) || 
												(strcasecmp(param->attribute,"name") == 0))) {
						v = fe_new_str("filename", param->value, 0, FE_CHARSET_DEFAULT );
						ferite_object_set_var(script, VAO(object), "filename", v );
						break;
					}
					param = param->next;
				}
			}
		}
		return object;
	}
	return NULL;
}
Exemplo n.º 11
0
void builder_process_closed_class( FeriteScript *script, FeriteClass *cls, char *parent )
{
    char buf[1024];

    FE_ENTER_FUNCTION;

    if( (char *)cls->parent != NULL ) /* we have a inheirted class */
    {
        if( !builder_class_in_stack( (char *)cls->parent ) ) /* it's not in the class stack */
        {
            FeriteNamespaceBucket *nsb = ferite_find_namespace( script, script->mainns, (char *)cls->parent, FENS_CLS );
            if( nsb != NULL )
            {
                builder_process_class( script, nsb->data, parent );
                ferite_stack_push( FE_NoScript, class_stack, fstrdup((char *)cls->parent) );
            }
            else
            {
                ferite_warning( script, "Class '%s' extends '%s' which does not exist in this module - assuming it is external\n", cls->name, (char*)cls->parent );
            }
        }
    }
    if( builder_class_in_stack( cls->name ) )
    {
        /* we return if we are already in the list */
        FE_LEAVE_FUNCTION(NOWT);
    }

    ferite_stack_push( FE_NoScript, current_module->name_stack, cls->name );
    sprintf( buf, "%s.c", builder_generate_current_name(FE_TRUE,FE_FALSE) );
    strcat( internal_file_list, buf ); strcat( internal_file_list, " " );
    if( opt.verbose )
      printf( "Generating file %s for class %s\n", buf, parent );
    ferite_stack_push( FE_NoScript, file_stack, module_current_c_file );
    module_current_c_file = builder_fopen( buf, "w" );

    fprintf( module_current_c_file,
             "/* This file has been automatically generated by builder part of the ferite distribution */\n" \
                         "/* file:  %s */\n" \
                         "/* class: %s */\n\n" \
                         "#include <ferite.h>       /* we need this without a doubt */\n" \
                         "#include \"%s_header.h\"  /* this is the module header */\n\n", buf, cls->name, current_module->name );

    fprintf( current_module->core, "   if( ferite_namespace_element_exists( script, %s_namespace, \"%s\" ) == NULL )\n" \
                                  "   {\n" \
                            "      FeriteClass *%s_%s_class = ferite_register_inherited_class( script, %s_namespace, \"%s\", %s%s%s );\n",
             builder_generate_current_name( FE_FALSE,FE_TRUE ),
             cls->name,
             builder_generate_current_name( FE_TRUE,FE_TRUE ),
             cls->name,
             builder_generate_current_name( FE_FALSE,FE_TRUE ),
             cls->name,
             ( cls->parent == NULL ? "" : "\"" ),
             ( cls->parent == NULL ? "NULL" : (char *)cls->parent ),
             ( cls->parent == NULL ? "" : "\"" )
             );
    if( cls->parent != NULL )
    {
        ffree( cls->parent );
    }
    in_class = 1;
	ferite_process_hash( script, cls->object_vars, (void (*)(FeriteScript*,void *,char*))builder_process_variable );
    ferite_process_hash( script, cls->class_vars, (void (*)(FeriteScript*,void *,char*))builder_process_variable );
    ferite_process_hash( script, cls->object_methods, (void (*)(FeriteScript*,void *,char*))builder_process_function );
    ferite_process_hash( script, cls->class_methods, (void (*)(FeriteScript*,void *,char*))builder_process_function );
    in_class = 0;
    fprintf( current_module->core, "   }\n\n" );

    fclose( module_current_c_file );
    module_current_c_file = ferite_stack_pop( FE_NoScript, file_stack );
    ferite_stack_pop( FE_NoScript, current_module->name_stack );
    FE_LEAVE_FUNCTION( NOWT );
}
Exemplo n.º 12
0
void game_engine_init( FeriteScript *script )
{
	FeriteNamespaceBucket *nsb = ferite_find_namespace(script, script->mainns, "Engine", FENS_NS);
	FeriteNamespace *engine_namespace = (nsb && nsb->data ? nsb->data : ferite_register_namespace(script, "Engine", script->mainns));
	
	FeriteVariable *event_keydown_variable = ferite_create_number_long_variable(script, "EVENT_KEYDOWN", SDL_KEYDOWN, FE_STATIC);
	FeriteVariable *event_keyup_variable = ferite_create_number_long_variable(script, "EVENT_KEYUP", SDL_KEYUP, FE_STATIC);
	FeriteVariable *event_mousebuttondown_variable = ferite_create_number_long_variable(script, "EVENT_MOUSEBUTTONDOWN", SDL_MOUSEBUTTONDOWN, FE_STATIC);
	FeriteVariable *event_mousebuttonup_variable = ferite_create_number_long_variable(script, "EVENT_MOUSEBUTTONUP", SDL_MOUSEBUTTONUP, FE_STATIC);
	FeriteVariable *event_mousemotion_variable = ferite_create_number_long_variable(script, "EVENT_MOUSEMOTION", SDL_MOUSEMOTION, FE_STATIC);
	FeriteVariable *event_quit_variable = ferite_create_number_long_variable(script, "EVENT_QUIT", SDL_QUIT, FE_STATIC);
	
	FeriteVariable *button_left_variable = ferite_create_number_long_variable(script, "BUTTON_LEFT", SDL_BUTTON_LEFT, FE_STATIC);
	
	FeriteFunction *sin_function = ferite_create_external_function(script, "sin", game_engine_sin, "n");
	FeriteFunction *cos_function = ferite_create_external_function(script, "cos", game_engine_cos, "n");
	FeriteFunction *print_line_function = ferite_create_external_function(script, "printLine", game_engine_print_line, "s");
	FeriteFunction *set_screen_function = ferite_create_external_function(script, "setScreen", game_engine_set_screen, "nnn");
	FeriteFunction *clear_screen_function = ferite_create_external_function(script, "clearScreen", game_engine_clear_screen, "");
	FeriteFunction *update_screen_function = ferite_create_external_function(script, "updateScreen", game_engine_update_screen, "");
	FeriteFunction *next_event_function = ferite_create_external_function(script, "nextEvent", game_engine_next_event, "");
	FeriteFunction *current_time_function = ferite_create_external_function(script, "currentTime", game_engine_current_time, "");
	FeriteFunction *load_image_function = ferite_create_external_function(script, "loadImage", game_engine_load_image, "sn");
	FeriteFunction *draw_image_function = ferite_create_external_function(script, "drawImage", game_engine_draw_image, "onnnnnn");
	FeriteFunction *screen_width_function = ferite_create_external_function(script, "screenWidth", game_engine_screen_width, "");
	FeriteFunction *screen_height_function = ferite_create_external_function(script, "screenHeight", game_engine_screen_height, "");
	FeriteFunction *current_working_directory_function = ferite_create_external_function(script, "currentWorkingDirectory", game_engine_current_working_directory, "");
	FeriteFunction *draw_rectangle_function = ferite_create_external_function(script, "drawRectangle", game_engine_draw_rectangle, "nnnnnnn");
	FeriteFunction *play_music_function = ferite_create_external_function(script, "playMusic", game_engine_play_music, "s");
	FeriteFunction *stop_music_function = ferite_create_external_function(script, "stopMusic", game_engine_stop_music, "");
	FeriteFunction *set_sound_channels_function = ferite_create_external_function(script, "setSoundChannels", game_engine_set_sound_channels, "n");
	FeriteFunction *load_sound_function = ferite_create_external_function(script, "loadSound", game_engine_load_sound, "s");

	ferite_register_inherited_class(script, engine_namespace, "KeyboardEvent", NULL);
	ferite_register_inherited_class(script, engine_namespace, "MouseButtonEvent", NULL);
	ferite_register_inherited_class(script, engine_namespace, "MouseMotionEvent", NULL);
	ferite_register_inherited_class(script, engine_namespace, "QuitEvent", NULL);
	
	ferite_register_ns_variable(script, engine_namespace, "EVENT_KEYDOWN", event_keydown_variable);
	ferite_register_ns_variable(script, engine_namespace, "EVENT_KEYUP", event_keyup_variable);
	ferite_register_ns_variable(script, engine_namespace, "EVENT_MOUSEBUTTONDOWN", event_mousebuttondown_variable);
	ferite_register_ns_variable(script, engine_namespace, "EVENT_MOUSEBUTTONUP", event_mousebuttonup_variable);
	ferite_register_ns_variable(script, engine_namespace, "EVENT_MOUSEMOTION", event_mousemotion_variable);
	ferite_register_ns_variable(script, engine_namespace, "EVENT_QUIT", event_quit_variable);
	
	// SDL_BUTTON_LEFT, SDL_BUTTON_MIDDLE, SDL_BUTTON_RIGHT, SDL_BUTTON_WHEELUP, SDL_BUTTON_WHEELDOWN
	ferite_register_ns_variable(script, engine_namespace, "BUTTON_LEFT", button_left_variable);
	
	ferite_register_ns_function(script, engine_namespace, sin_function);
	ferite_register_ns_function(script, engine_namespace, cos_function);
	ferite_register_ns_function(script, engine_namespace, print_line_function);
	ferite_register_ns_function(script, engine_namespace, set_screen_function);
	ferite_register_ns_function(script, engine_namespace, clear_screen_function);
	ferite_register_ns_function(script, engine_namespace, update_screen_function);
	ferite_register_ns_function(script, engine_namespace, next_event_function);
	ferite_register_ns_function(script, engine_namespace, current_time_function);
	ferite_register_ns_function(script, engine_namespace, load_image_function);
	ferite_register_ns_function(script, engine_namespace, draw_image_function);
	ferite_register_ns_function(script, engine_namespace, screen_width_function);
	ferite_register_ns_function(script, engine_namespace, screen_height_function);
	ferite_register_ns_function(script, engine_namespace, current_working_directory_function);
	ferite_register_ns_function(script, engine_namespace, draw_rectangle_function);
	ferite_register_ns_function(script, engine_namespace, play_music_function);
	ferite_register_ns_function(script, engine_namespace, stop_music_function);
	ferite_register_ns_function(script, engine_namespace, set_sound_channels_function);
	ferite_register_ns_function(script, engine_namespace, load_sound_function);
	
	game_engine_key_init(script, engine_namespace);
	game_engine_image_init(script, engine_namespace);
	game_engine_sound_init(script, engine_namespace);
	game_engine_network_init(script);
}