mozilla

Compare Revisions

Working with data

Change Revisions

Revision 98266:

Revision 98266 by Sheppy on

Revision 98267:

Revision 98267 by Sheppy on

Title:
Working with data
Working with data
Slug:
Mozilla/js-ctypes/Using_js-ctypes/Working_with_data
Mozilla/js-ctypes/Using_js-ctypes/Working_with_data
Tags:
JavaScript, js-ctypes
JavaScript, js-ctypes
Content:

Revision 98266
Revision 98267
tt141      Working with strings
142    </h2>
143    <p>
144      C functions expect strings to be arrays of characters, with
 > the end of the string indicated by a null character. JavaScript,
 > on the other hand, uses the <a href="/en/Core_JavaScript_1.5_Ref
 >erence/Global_Objects/String" title="en/Core JavaScript 1.5 Refer
 >ence/Global Objects/String"><code>String</code></a> object to rep
 >resent strings.
145    </p>
146    <h3>
147      Converting C strings to JavaScript
148    </h3>
149    <p>
150      The <a href="/en/js-ctypes/js-ctypes_reference/CData" title
 >="en/js-ctypes/js-ctypes reference/CData"><code>CData</code></a> 
 >object provides the <a href="/en/js-ctypes/js-ctypes_reference/CD
 >ata#readString()" title="en/js-ctypes/js-ctypes reference/CData#r
 >eadString()"><code>readString()</code></a>&nbsp;method, which rea
 >ds bytes from the specified string and returns a new JavaScript <
 >a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/String" 
 >title="en/Core JavaScript 1.5 Reference/Global Objects/String"><c
 >ode>String</code></a> object representing that string.
151    </p>
152    <div class="note">
153      <strong>Note:</strong> The source C string is assumed to be
 > UTF-8, and is assumed to be null terminated. If you need to conv
 >ert a string that doesn't meet these requirements, you'll need to
 > do it yourself.
154    </div>
155    <p>
156      For example:
157    </p>
158    <pre>
159var jsString = timeStr.readString();
160</pre>
161    <h3>
162      Converting JavaScript strings to C
163    </h3>
164    <p>
165      <em>work in progress</em>
166    </p>
167    <h2>

Back to History