[Ecls-list] ecl_def_c_function with a non-void function
Erik Winkels
aerique at xs4all.nl
Mon Apr 12 12:45:50 UTC 2010
Hi,
I seem to be on my biannual ECL exploration.
(Also see the code listing at the bottom of this e-mail.)
I'm playing around with ecl_def_c_function and this works:
ecl_def_c_function(ecl_read_from_cstring("test-void"), &test_void, 0);
If I do "(test-void)" from the ECL repl I get the expected ":TEST-VOID"
result.
However, this gives compilation errors for me:
ecl_def_c_function(ecl_read_from_cstring("test-2args"), &test_2args, 2);
Namely:
$ g++ -lecl -otest test.cpp
test.cpp: In function 'int main(int, char**)':
test.cpp:28: error: invalid conversion from 'cl_lispunion* (*)(cl_lispunion*, cl_lispunion*)' to 'cl_lispunion* (*)()'
test.cpp:28: error: initializing argument 2 of 'void ecl_def_c_function(cl_lispunion*, cl_lispunion* (*)(), int)'
I can understand why but I haven't been able to write the correct
ecl_def_c_function to make this work. I've tried some approaches myself and
I've tried thing I found by Googling but those seem to have been written
for an older ECL version.
Code:
// test.cpp
//
// compiling: g++ -lecl -otest test.cpp
//
// o http://www.den.rcast.u-tokyo.ac.jp/~salvi/archive/snippets/ecl-test.html
// o http://code.google.com/p/m-nebula/source/browse/#svn/trunk/code/src/ecl
#include <iostream>
#include "ecl/ecl.h"
// Prototypes
cl_object test_void ();
cl_object test_2args (cl_object, cl_object);
// Functions
int main (int argc, char* args[])
{
cl_boot(argc, args);
// We are computing unnormalized numbers at some point.
//si_trap_fpe(Ct, Cnil);
ecl_def_c_function(ecl_read_from_cstring("test-void"), &test_void, 0);
ecl_def_c_function(ecl_read_from_cstring("test-2args"), &test_2args, 2);
cl_object obj = ecl_read_from_cstring("si:top-level");
cl_funcall(1, obj);
cl_shutdown();
return 0;
}
cl_object test_2args (cl_object first, cl_object second)
{
std::cout << "first: " << type_of(first) << ", second: " << type_of(second)
<< std::endl;
return ecl_read_from_cstring(":test-2args");
}
cl_object test_void ()
{
return ecl_read_from_cstring(":test-void");
}
More information about the ecl-devel
mailing list