Thank you!
This looks interesting - and definately a new area of Perl for me...
I tried to compile it but ran into an error:
TellStick.xs:70:10: error: ‘sv’ undeclared (first use in this function
+)
I guess sv needs to be declared. And there was a typo for
NewSViv.
So now it looks like
if (rv == TELLSTICK_SUCCESS) {
HV* hv = newHV();
SV *sv = newSV(0);
sv = newSVpv(protocol, 0); hv_stores(hv, "protocol", sv);
sv = newSVpv(model, 0); hv_stores(hv, "model", sv);
sv = newSViv(id); hv_stores(hv, "id", sv);
sv = newSViv(dataTypes); hv_stores(hv, "dataTypes", sv);
RETVAL = newRV_noinc(hv);
} else {
RETVAL = &PL_sv_undef;
}
There were some compilation warnings as well, don't know if they are important:
In file included from /usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/perl
+.h:5102:0,
from TellStick.xs:2:
TellStick.xs: In function ‘XS_TellStick_tdSensor’:
TellStick.xs:76:31: warning: passing argument 2 of ‘Perl_newRV_noinc’
+from incompatible pointer type
RETVAL = newRV_noinc(hv);
^
/usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/embed.h:371:48: note: in d
+efinition of macro ‘newRV_noinc’
#define newRV_noinc(a) Perl_newRV_noinc(aTHX_ a)
^
In file included from /usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/perl
+.h:5061:0,
from TellStick.xs:2:
/usr/lib/arm-linux-gnueabihf/perl/5.20/CORE/proto.h:2874:19: note: exp
+ected ‘struct SV * const’ but argument is of type ‘struct HV *’
PERL_CALLCONV SV* Perl_newRV_noinc(pTHX_ SV *const sv)
But the code works!!!
I get the correct values:
protocol: mandolyn, model: temperaturehumidity, sensorId: 51, dataType
+s: 3
protocol: mandolyn, model: temperaturehumidity, sensorId: 61, dataType
+s: 3
Thank you very much for your help! Now I have a way forward for implementing the rest of fucntion in the C library.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.