MzMisc Reference Manual
<<< Previous Page Home Up Next Page >>>

General

Name

General — library initialization and miscellaneous functions.

Synopsis

#include <mzmisc/mzmisc.h>
struct mz_proxy
Scheme_Object> mz_make_proxy (Scheme_Type type
 void *proxy)
#define MZ_PROXY_VAL (p)
#define MZ_PRIM_END
#define MZ_PRIM_DECL (f)
#define MZ_NAME (a,i)
struct mz_prim

Description

This section describes the MzMisc initialization functions and miscellaneous utility functions.

Details

struct mz_proxy

typdef struct _mz_proxy {
  Scheme_Type type
  void *object
} mz_proxy

Wrapper for new scheme objects

type scheme object.type
object pointer to the wrapped object.

mz_make_proxy

Scheme_Object *mz_make_proxy (Scheme_Type type,
 void *object)

Creates a scheme object wrapper for object

type scheme object type.
object pointer to the wrapped object.
Returns a new scheme object that wraps object.

Example: Creating a new type of scheme object

Scheme_Type    new_type;
Scheme_Object *new_object;

new_type = mz_make_type( "<SomeNewType>" );
new_object = mz_make_proxy( new_type, some_func() );

MZ_PROXY_VAL

#define *MZ_PROXY_VAL (proxy)

Returns the object being wrapped by the proxy

proxy wrapped object
Returns the object being wrapped by the proxy

MZ_PRIM_END

#define MZ_PRIM_END  

Used to end static primitive definition array

Example: Ending primitives

static mz_prim my_primitives[] = {
  { &my_names[1], some_func, 0, 0 },
  MZ_PRIM_END
};

MZ_PRIM_DECL

#define MZ_PRIM_DECL (f)

Forward declaration for scheme primitives

f scheme primitive

Example: Declaring primitives

MZ_PRIM_DECL( some_func );

MZ_NAME

#define MZ_NAME (a,i)

Used to end static primitive definition array

a array of strings
i index into array
Returns the string at i in a

struct mz_prim

typedef struct _mz_primitive {
  char **name
  Scheme_Object *(*func)(int argc, Scheme_Object **argv)
  short min
  short max
} mz_prim

Definition for scheme procedure

name function name
func the fuction
min minimum number of parameters
max maximum number of parameters

Example: Creating primitives

static char *my_names[] = {
  "some_func_name",
  NULL
};

typedef enum {
  SOME_FUNC
} MyNamesIndex;

MZ_PRIM_DECL( some_func );

#define MY_NAME(i) MZ_NAME(my_names, i)

#define SOME_FUNC_NAME MY_NAME( SOME_FUNC )

static mz_prim my_primitives[] = {
  { &( SOME_FUNC_NAME ), some_func, 0, 0 },
  MZ_PRIM_END
};

Scheme_Object *some_func(int argc, char *argv[]) {
  return scheme_make_string( "blah" );
}


<<< Previous Page Home Up Next Page >>>
MzMisc

Last modified: Wed Mar 19 20:16:34 EST 2003