const LV2_Descriptor* lv2_descriptor(uint32_t index) { int lv2_desc_index; initialize_plugin_internals(); initialize_ecl(); // Trampoline this request to the ECL side, then unpack the resultant // return value into something suitable for the caller. cl_object obj = cl_funcall(2, c_string_to_object("lv2-descriptor"), MAKE_FIXNUM(index)); printf("C: lv2_descriptor got from lisp:"); cl_pprint(1, obj); cl_princ(1, c_string_to_object("#\\Newline")); if (obj == Cnil) { // Don't make an association in this case. return NULL; } // Associate the lisp description with a C address of a real LV2_Descriptor lv2_desc_index = da_allocate(); da_associate(lv2_desc_index, obj); // The application will use this to talk about this specific plugin. return da_get_address(lv2_desc_index); }
int main(int narg, char **argv) { pthread_t child_thread; int i, code; /* * First of all, we have to initialize the ECL environment. * This should be done from the main thread. */ cl_boot(narg, argv); /* * Here we spawn 10 threads using the OS functions. The * current version is for Unix and uses pthread_create. * Since we have included <gc.h>, pthread_create will be * replaced with the appropiate routine from the garbage * collector. */ cl_object sym_print = c_string_to_object("PRINT"); /* * This array will keep the forms we want to evaluate from * being garbage collected. */ volatile cl_object forms[4]; for (i = 0; i < 4; i++) { forms[i] = cl_list(2, sym_print, MAKE_FIXNUM(i)); code = pthread_create(&child_thread, NULL, thread_entry_point, (void*)forms[i]); if (code) { printf("Unable to create thread\n"); exit(1); } } /* * Here we wait for the last thread to finish. */ pthread_join(child_thread, NULL); return 0; }
int ecl_boot(const char *root_dir) { int argc = 1; char *argv[256]; argv[0] = "ecl"; GC_allow_register_threads(); GC_register_my_thread((const struct GC_stack_base *)argv); GC_stackbottom = (void*)(argv+255); setenv("ECLDIR", "", 1); cl_boot(argc, argv); main_lib_ECL_HELP(); main_lib_ASDF(); main_lib_SOCKETS(); main_lib_IPHONEPSYSTEM(); si_select_package(ecl_make_simple_base_string("CL-USER", 7)); char tmp[2048]; sprintf(tmp, "(setq *default-pathnames-defaults* #p\"%s\")", root_dir); si_safe_eval(3, c_string_to_object(tmp), Cnil, OBJNULL); init_callbacks_registry(); ecl_toplevel(root_dir); return 0; }
std::string ECL::echo(const std::string &s) const { cl_object o = cl_funcall(2, c_string_to_object("echo"), ecl_make_pointer((void*)s.c_str())); return (char*)ecl_to_pointer(o); }
int ECL::init() { cl_eval(c_string_to_object("(defun echo (x) x)")); return 0; }
// Create a new plugin instance. static LV2_Handle instantiate(const LV2_Descriptor* descriptor, double rate, const char* bundle_path, const LV2_Feature* const* features) { char *real_string = NULL; int lv2_desc_index; int lv2_handle_index; DescAssoc *da = NULL; LV2_Handle ret; // lookup the DescAssoc with this descripter pointer lv2_desc_index = da_get_index(descriptor); da = da_get_da(lv2_desc_index); printf("C: instantiate() for LV2_Desc called:\n" "\tlv2_desc_index = %d\n" "\tdescriptor = %p\n" "\trate = %f\n" "\tbundle path = %s\n" "\tfeatures array = %p\n", lv2_desc_index, descriptor, rate, bundle_path, features); // Call the mirrored lisp instantiate function from the associated // lisp version of the lv2-descriptor. This is going to return a // cl_object that represents an LV2_Handle. // first, get the function we need to call from the right lisp lv2 // descriptor. cl_object lisp_instantiate_function = cl_funcall(2, c_string_to_object("lv2-instantiate"), da->lisp_lv2_desc); // Then call it, passing the usual stuff. lisp will return to us the // handle it wants back. real_string = stringify(bundle_path); cl_object lisp_handle = cl_funcall(5, lisp_instantiate_function, da->lisp_lv2_desc, ecl_make_double_float(rate), c_string_to_object(real_string), Cnil); free(real_string); // Associate the lisp_handle with a duck handle we're going to give to the // host. lv2_handle_index = hda_allocate(); hda_associate(lv2_handle_index, lv2_desc_index, lisp_handle); // Then, return the fake LV2_Handle to the host. ret = hda_get_address(lv2_handle_index); return ret; }
// Make sure this doesn't get called before 'cl_boot' int lisp_add(int x, int y) { cl_object sum = cl_funcall(3, c_string_to_object("add"), ecl_make_int(x), ecl_make_int(y)); return ecl_to_int(sum); }
void ecl_toplevel(const char *home) { char tmp[512]; sprintf(tmp, "(load \"%s/%s\")", home, "init.lisp"); si_safe_eval(3, c_string_to_object(tmp), Cnil, OBJNULL); }