source: trunk/lang/perl/Rappture.xs @ 1716

Last change on this file since 1716 was 1716, checked in by mmc, 11 years ago

Fixed the Perl bindings to handle binary data properly. Users on vhub.org
stumbled into this. Image data was getting truncated on the first embedded
null byte, instead of keeping the entire length of the binary data.

File size: 2.0 KB
Line 
1#include "rappture.h"
2#include <string>
3
4#include "EXTERN.h"
5#include "perl.h"
6#include "XSUB.h"
7
8#include "ppport.h"
9
10using namespace std;
11
12MODULE = Rappture        PACKAGE = Rappture::RpLibrary
13PROTOTYPES: ENABLE
14
15RpLibrary *
16RpLibrary::new(filename = "")
17const char *filename
18    CODE:
19        RpLibrary *library;
20        if ((filename == NULL) || (*filename == '\0'))
21            library = new RpLibrary();
22        else
23            library = new RpLibrary(filename);
24
25        if (library->isNull())
26                {
27                        delete library;
28            XSRETURN_UNDEF;
29                }
30        else
31            RETVAL = library;
32    OUTPUT:
33        RETVAL
34
35void *
36RpLibrary::DESTROY()
37    CODE:
38        RETVAL = 0;
39
40SV *
41RpLibrary::get( path )
42const char *path
43    CODE:
44        string result;
45        result = THIS->get(path);
46        RETVAL = newSVpvn(result.data(),result.length());
47    OUTPUT:
48        RETVAL
49
50void
51RpLibrary::put( path, value, append )
52const char *path
53const char *value
54int append
55    CODE:
56        THIS->put(path,value,"",append);
57
58void
59RpLibrary::putFile( path, fileName, compress, append )
60const char *path
61const char *fileName
62int compress
63int append
64    CODE:
65        THIS->putFile(path,fileName,compress,append);
66
67void
68RpLibrary::result()
69    CODE:
70        THIS->put("tool.version.rappture.language", "perl");
71        THIS->result();
72
73MODULE = Rappture        PACKAGE = Rappture::RpUnits
74
75const char *
76convert( fromVal, toUnitsName, showUnits = 1 )
77const char *fromVal
78const char *toUnitsName
79int showUnits
80    CODE:
81        string result;
82        result = RpUnits::convert(fromVal,toUnitsName,showUnits);
83
84                if (result.empty())
85                    XSRETURN_UNDEF;
86
87        RETVAL = result.c_str();
88    OUTPUT:
89        RETVAL
90
91MODULE = Rappture        PACKAGE = Rappture::Utils
92
93int
94progress( percent, message )
95int percent
96const char *message
97    CODE:
98        RETVAL = Rappture::Utils::progress(percent,message);
99    OUTPUT:
100        RETVAL
Note: See TracBrowser for help on using the repository browser.