Hi, I'm writing a wrapper for a game engine that involves a few callbacks. I wrap the callback in a C function so that I can pass in lambdas as callbacks. Here is how the code looks like:
cl_object callback_wrapper(cl_object lambda, cl_object ...) { cl_funcall(2, lambda, some_params); }
It works OK if the passed in lambda function is syntactically correct. But it fails disastrously if the function contains errors, either syntactically or logically and it crashes the program. I wonder if it's possible to call the lambda function in a safer manner and when anything is wrong, it just drops to the top-level?
A second question is... can I traverse lisp lists in C? I would like to collect everything into a C++ vector and pass that on to the engine's API.
Thanks, Bruce
2015-09-08 18:15 GMT+02:00, bruce li leilmyxwz@gmail.com:
cl_object callback_wrapper(cl_object lambda, cl_object ...) { cl_funcall(2, lambda, some_params); }
It works OK if the passed in lambda function is syntactically correct. But it fails disastrously if the function contains errors...
Please note: the code snippets are taken from EQL. (I hope this helps.)
Fully protected function calls:
const cl_env_ptr l_env = ecl_process_env(); CL_CATCH_ALL_BEGIN(l_env) { CL_UNWIND_PROTECT_BEGIN(l_env) { cl_funcall(1, (cl_object)function); } CL_UNWIND_PROTECT_EXIT {} CL_UNWIND_PROTECT_END; } CL_CATCH_ALL_END;
A second question is... can I traverse lisp lists in C? I would like to collect everything into a C++ vector and pass that on to the engine's API.
Trivial traversing of Lisp lists:
QStringList l; if(LISTP(l_list)) { cl_object l_el = l_list; while(l_el != Cnil) { l << toQString(cl_car(l_el)); l_el = cl_cdr(l_el); } }