root/lang/perl/Senna/trunk/senna-records.c @ 3911

Revision 3911, 1.7 kB (checked in by daisuke, 6 years ago)

more code... (things are still broken)

Line 
1#ifndef __SENNA_RECORDS_C__
2#define __SENNA_RECORDS_C__
3
4#include "senna-perl.h"
5
6SV *
7SennaPerl_Records_new(pkg, records)
8        char *pkg;
9        sen_records *records;
10{
11    SennaPerl_Records *xs;
12    SV *sv;
13
14    Newz(1234, xs, 1, SennaPerl_Records);
15
16    xs->records = records;
17
18    XS_STRUCT2OBJ(sv, pkg, xs);
19    SvREADONLY_on(sv);
20    return sv;
21}
22
23SV *
24SennaPerl_Records_next(obj)
25        SV *obj;
26{
27    SV *sv;
28    char keybuf[SEN_MAX_KEY_SIZE];
29    int score;
30    SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj);
31
32    if (sen_records_next(records->records, &keybuf, SEN_MAX_KEY_SIZE, &score)) {
33        dSP;
34        ENTER;
35        SAVETMPS;
36        PUSHMARK(SP);
37
38        XPUSHs(sv_2mortal(newSVpv("Senna::Record", 13)));
39        XPUSHs(sv_2mortal(newSVpv("key", 3)));
40        XPUSHs(sv_2mortal(newSVpv(keybuf, 0)));
41        XPUSHs(sv_2mortal(newSVpv("score", 5)));
42        XPUSHs(sv_2mortal(newSViv(score)));
43        PUTBACK;
44        if (call_method("Senna::Record::new", G_SCALAR) <= 0) {
45            croak ("Senna::Record::new did not return an object ");
46        }
47        SPAGAIN;
48        sv = POPs;
49
50        if (! SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV ) {
51            croak ("Senna::Record::new did not return a proper object");
52        }
53
54        FREETMPS;
55        LEAVE;
56
57        return sv;
58    }
59    return &PL_sv_undef;
60}
61
62SV *
63SennaPerl_Records_nhits(obj)
64        SV *obj;
65{
66    SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj);
67    return newSViv( sen_records_nhits( records->records ) );
68}
69
70SV *
71SennaPerl_Records_DESTROY(obj)
72        SV *obj;
73{
74    SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj);
75    sen_records_close(records->records);
76    Safefree(records);
77}
78
79#endif /* __SENNA_RECORDS_C__ */
Note: See TracBrowser for help on using the browser.