document sexp_lookup_type (issue #718)

This commit is contained in:
Alex Shinn 2020-11-25 14:36:54 +09:00
parent 79e76b295f
commit 54f55569e2
2 changed files with 15 additions and 4 deletions

View file

@ -938,16 +938,27 @@ NULL in which case the pointers are never freed, or otherwise a
procedure of one argument which should release any resources.
}}
\item{\ccode{sexp sexp_make_cpointer(sexp ctx, sexp_uint_t type_id, void* value, sexp parent, int freep)}
\item{\ccode{sexp sexp_make_cpointer(sexp ctx, sexp_uint_t type_tag, void* value, sexp parent, int freep)}
\p{
Creates a new instance of the type indicated by type_id wrapping
Creates a new instance of the type indicated by type_tag wrapping
value. If parent is provided, references to the child will also
preserve the parent, important e.g. to preserve an enclosing struct
when wrapped references to nested structs are still in use. If freep
is true, then when reclaimed by the GC the finalizer for this type,
if any, will be called on the instance.
You can retrieve the id from a type object with sexp_type_tag(type).
You can retrieve the tag from a type object with sexp_type_tag(type).
}}
\item{\ccode{sexp sexp_lookup_type(sexp ctx, sexp name, sexp tag_or_id)}
\p{
Returns the type whose name matches the string \var{name}. If
\var{tag_or_id} is an integer, it is taken as the tag and requires the
numeric type tag (as from sexp_type_tag) to also match.
}
\p{If \var{tag_or_id} is a string, it is taken as the unique id of the
type, and must match sexp_type_id(type). However, currently
sexp_type_id(type) is never set.
}}
]

2
sexp.c
View file

@ -440,7 +440,7 @@ sexp sexp_lookup_type_op(sexp ctx, sexp self, sexp_sint_t n, sexp name, sexp id)
if (sexp_stringp(id)
&& !(sexp_stringp(sexp_type_id(res))
&& strcmp(sexp_string_data(id), sexp_string_data(sexp_type_id(res))) == 0))
return SEXP_FALSE;
continue;
return res;
}
return SEXP_FALSE;