[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add pseudo vector types

From: Stefan Monnier
Subject: Re: How to add pseudo vector types
Date: Wed, 14 Jul 2021 13:47:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Yuan Fu [2021-07-14 13:37:47] wrote:
> Say I want to expose tree-sitter’s parser to lisp, and I define it as a new 
> pseudo vector.
> struct Lisp_TS_Parser
> {
>   union vectorlike_header header;
>   Lisp_Object buffer;
>   TSParser *parser;
>   TSTree *tree;
>   TSInput input;
> };
> Now if I want to return a Lisp_Object, do I initialize this struct and cast
> it into a Lisp_Object and return it? Like:
> Lisp_TS_parser lisp_parser;
> ...
> return (Lisp_Object)lisp_parser;
> And how do I use a USER_PTR? Do I cast it into (struct Lisp_User_Ptr) and
> use it normally, or is there some helper function that I should use?

Most likely you'll want some of your functions to take objects that
should be "tree sitter parsers", but you'll only receive a Lisp_Object
so you'll need to be able to *test* that the object you received is
indeed a "tree sitter parser".

For that reason you'll probably want to add a new entry to `pvec_type`
rather than use a USER_PTR.

> Are there examples of using pseudo vectors? Thanks

Lots of them: actual vectors, processes, threads, mutexes, overlays, you
name it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]