[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to create a struct in a Mzscheme extension.



Hi people,

I am trying to create a struct type from inside my mzscheme extension.

{Env: Windows NT 4.0 SP4, DrScheme 101, Visual C++ 6.0 SP3)

This is what I came up with so far.

// Function to create a new struct.

Scheme_Object* new_scheme_struct (Scheme_Env* env, const char* basename, int
num_fields, char** field_names)
{
	Scheme_Object* new_type;

	Scheme_Object** a = (Scheme_Object**)
scheme_malloc(num_fields*sizeof(Scheme_Object*)); 

	for (int i=0; i<num_fields; ++i){
	    a[i] = (Scheme_Object*) scheme_intern_symbol(field_names[i]);
	}
	
	new_type = scheme_make_struct_type(scheme_intern_symbol(basename),
                                            NULL /*super_type*/, 
                                            num_fields); 
	int count_out;
	Scheme_Object** struct_names;

	struct_names =
scheme_make_struct_names(scheme_intern_symbol(basename), 
	
scheme_build_list(num_fields,a), 
									0
/*flags*/, 
	
&count_out); 

	scheme_make_struct_values(new_type, struct_names, count_out, 0); 

	return new_type;
}

.
.
.

// I call the function like this from my scheme_initialize()

	const char* field_names[] = {"id", "name", "type", "flags",
"disporder"};
	new_scheme_struct(env,"fieldinfo", 5, (char**) field_names);

After loading the extention I expected the following to work.

 (define f (make-fieldinfo 10 "FirstName" "String" 1.1 10))

But I am getting "reference to undefined identifier: make-fieldinfo".

Is there something more I need to do in the above code?. (Something like
"Need to add this typename to the Global environment" etc.) I was not able
to find anything more in the subject from "inside mzschme".

Any pointers ?
Appreciate your time.

pj