1 //------------------------------------------------------------------------------
3 // desc: source for ChucK DLL (foo.ckx) - an example
5 // authors: Ge Wang (gewang@cs.princeton.edu)
6 // Perry R. Cook (prc@cs.princeton.edu)
9 // *see http://chuck.cs.princeton.edu/ for complete documentation
11 // compile this file in the following way:
13 // > gcc -shared -I$(CHUCK_DIR) foo_ckx.cpp -o foo.ckx -lstdc++
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 //------------------------------------------------------------------------------
26 #include "chuck_ugen.h"
28 // query function prototype
31 // functions to export
32 DLL_FUNC
bar( void * ARGS
, Chuck_DL_Return
* RETURN
);
33 DLL_FUNC
sum( void * ARGS
, Chuck_DL_Return
* RETURN
);
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 )
42 QUERY
->set_name( QUERY
, "foo" );
45 QUERY
->add_export( QUERY
, "int", "bar", bar
, TRUE
);
46 QUERY
->add_param( QUERY
, "int", "x" );
49 QUERY
->add_export( QUERY
, "float", "sum", sum
, TRUE
);
50 QUERY
->add_param( QUERY
, "float", "lhs" );
51 QUERY
->add_param( QUERY
, "float", "rhs" );
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 );
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
;