*** empty log message ***
[chuck-blob.git] / ckx / foo.cpp
blobe295847d7ab641d24277c68f62c626bbe94d0a30
1 //------------------------------------------------------------------------------
2 // name: foo_ckx.cpp
3 // desc: source for ChucK DLL (foo.ckx) - an example
4 //
5 // authors: Ge Wang (gewang@cs.princeton.edu)
6 // Perry R. Cook (prc@cs.princeton.edu)
7 // date: Spring 2004
8 //
9 // *see http://chuck.cs.princeton.edu/ for complete documentation
11 // compile this file in the following way:
12 // LINUX/CYGWIN:
13 // > gcc -shared -I$(CHUCK_DIR) foo_ckx.cpp -o foo.ckx -lstdc++
14 // MacOS X:
15 // > gcc -bundle -I$(CHUCK_DIR) foo_ckx.cpp -o foo.ckx -lstdc++
17 // ChucK DLL description:
18 // - every DLL should have exactly one query-function called 'ck_query'
19 // - for every exported function there should be
20 // - the implementation function
21 // for example, to export the function 'int foo( int x )'
22 // - the implementation
23 // 'CK_DLL_EXPORT(void) foo( void * ARGS, Chuck_DL_Return * RETURN )'
24 //------------------------------------------------------------------------------
25 #include "chuck_dl.h"
26 #include "chuck_ugen.h"
28 // query function prototype
29 CK_DLL_QUERY;
31 // functions to export
32 DLL_FUNC bar( void * ARGS, Chuck_DL_Return * RETURN );
33 DLL_FUNC sum( void * ARGS, Chuck_DL_Return * RETURN );
35 // ugen prototypes
37 // ChucK DLL query function
38 // note: this uses the CK_DLL_QUERY macro which expands to:
39 // CK_DLL_EXPORT(t_CKBOOL) ck_query( Chuck_DL_Query * QUERY )
40 CK_DLL_QUERY
42 QUERY->set_name( QUERY, "foo" );
44 // add foo
45 QUERY->add_export( QUERY, "int", "bar", bar, TRUE );
46 QUERY->add_param( QUERY, "int", "x" );
48 // add sum
49 QUERY->add_export( QUERY, "float", "sum", sum, TRUE );
50 QUERY->add_param( QUERY, "float", "lhs" );
51 QUERY->add_param( QUERY, "float", "rhs" );
53 return TRUE;
57 // ChucK DLL implementation for 'bar'
58 // note: this uses the DLL_FUNC macro which expands to:
59 // CK_DLL_EXPORT(void)
60 DLL_FUNC bar( void * ARGS, Chuck_DL_Return * RETURN )
62 RETURN->v_int = *((int *)ARGS) + 1;
66 // ChucK DLL implementation for 'sum'
67 // note: this uses the CK_DLL_FUNC(x) macro which expands to:
68 // CK_DLL_EXPORT(void) x(void *ARGS, Chuck_DL_Return * RETURN );
69 CK_DLL_FUNC(sum)
71 // use a struct
72 struct s_sum{ t_CKFLOAT lhs; t_CKFLOAT rhs; };
74 s_sum * s = (s_sum*)ARGS;
75 RETURN->v_float = s->lhs + s->rhs;