Wrap a function returning an object

17 views
Skip to first unread message

Hleb

unread,
May 22, 2023, 4:49:59 AM5/22/23
to chibi-scheme
Hi!

I have some methods returning objects instead of pointers, e.g. (simplified)
=======
class Selection{void*ptr; int type;};
Selection find(const char*);
=======
If I use (define-c Selection find (string)) the generated code assumes that a pointer is returned: sexp_make_cpointer(ctx, sexp_unbox_fixnum(sexp_opcode_return_type(self)), find(sexp_string_data(arg0)), SEXP_FALSE, 0);

How to properly handle such cases? My current attempt is
========
auto *sel = static_cast<Selection*>(sexp_alloc(ctx, sizeof(Selection)));
*sel = find(s);
return sexp_make_cpointer(ctx, sexp_type_tag(SelectionType), sel, nullptr, 0);
========
But i'm not sure.

Reply all
Reply to author
Forward
0 new messages