[PD-dev] External development: preventing several copies of external

Martin Peach chakekatzil at gmail.com
Sun Jun 14 22:44:12 CEST 2015


On Sun, Jun 14, 2015 at 3:36 PM, Alexandre Clément <
alexandre.r.clement at gmail.com> wrote:

> Hello all!
>
> I'm creating an external which should only allow one copy loaded at the
> same time.
> Is there a way to check this upon creation?
>
> I tried going the same approach as checking if a receiver exists before
> attempting to send, but it doesn't seem to work.
>
> if (gensym("class_name")->s_thing) {
>     post("Exists!");
>     return false;
> }
>
> Because gensym generates the symbol if it wasn't already in the list.
What I do is have a global variable outside the class struct and check if
it is not zero before instantiating a new object.
Since c is guaranteed to initialize globals to zero, the first object
created can set it to some other value. Maybe some more trickery will be
needed if the object is deleted and recreated, possibly the code is still
in memory and the global will have the non-zero value; in this case the
free routine should zero the global,

Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20150614/47ea8f1f/attachment.html>


More information about the Pd-dev mailing list