in reply to (XS): returning an iterator.

I did something similar for Sort::Key, emulating a closure in XS. The trick I used was to return a new XSUB with the state attached in a magic table.

The source code is here. The function returning the XSUB closure is _multikeysorter and there are two auxiliary functions _xclosure_make and _xclosure_defaults to set and retrieve the data attached to the XSUB.

Replies are listed 'Best First'.
Re^2: (XS): returning an iterator.
by BrowserUk (Patriarch) on Sep 23, 2010 at 09:45 UTC

    You make it look simple enough. But... :) where does cv come from in the following line from XS_Sort__Key__multikeysort?

    AV *defaults = _xclosure_defaults(aTHX_ cv);

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      It gets introduced by the XS macro.