我正在尝试进入 C++ 中嵌入的 Common Lisp 的迷人世界。我的问题是我无法从 C++ 中读取和打印由 ECL 中定义的 lisp 函数返回的字符串。
在 C++ 中,我有这个函数来运行任意 Lisp 表达式:
cl_object lisp(const std::string & call) {
return cl_safe_eval(c_string_to_object(call.c_str()), Cnil, Cnil);
}
我可以通过这种方式使用数字来做到这一点:
电汇:
(defun return-a-number () 5.2)
用 C++ 读取和打印:
auto x = ecl_to_float(lisp("(return-a-number)"));
std::cout << "The number is " << x << std::endl;
一切都设置好了,工作正常,但我不知道用字符串而不是数字来做。这是我尝试过的:
电汇:
(defun return-a-string () "Hello")
C++:
cl_object y = lisp("(return-a-string)");
std::cout << "A string: " << y << std::endl;
打印字符串的结果是这样的:
一个字符串:0x3188b00
我猜是字符串的地址。
这里是调试器的捕获和y cl_object 的内容。y->string.self 类型是一个 ecl_character。