Skip to content

Commit

Permalink
Make JavaScript strings work as CString without needing a trailing '\…
Browse files Browse the repository at this point in the history
…x00'
  • Loading branch information
hamishmack committed May 12, 2012
1 parent b39bece commit e660085
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/TestJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ window.onload = function() {
$hs_fromHaskellIO([$$$Test_test10()], function(i) {
$hs_fromHaskellInt([i], logResult, logException);}, logException);
}
$hs_force([$$GHCziCString_unpackCStringzh, "42\x00"], function(s42) {
$hs_force([$$GHCziCString_unpackCStringzh, "42"], function(s42) {
$hs_force([$$$Test_test11(), s42], function(i) {
$hs_fromHaskellInt([i], logResult, logException);}, logException);
$hs_fromHaskellIO([$$$Test_test12(), s42], function(i) {
Expand Down
8 changes: 4 additions & 4 deletions rts/rts-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,9 @@ var $hs_leAddrzh = function (a, b) {
};
var $hs_indexCharOffAddrzh = function (a, n) {
if(typeof(a) === 'string')
return a.charAt(n);
return n==a.length?'\x00':a.charAt(n);
else if(typeof(a[0]) === 'string')
return a[0].charAt(a[1]+n);
return n==a[0].length?'\x00':a[0].charAt(a[1]+n);
else
return String.fromCharCode(new Uint8Array(a[0],a[1]+n)[0]);
};
Expand Down Expand Up @@ -614,9 +614,9 @@ var $hs_indexInt64OffAddrzh = function (a, n) {
};
var $hs_indexWord8OffAddrzh = function (a, n) {
if(typeof(a) === 'string')
return a.charCodeAt(n);
return n==a.length?'\x00':a.charCodeAt(n);
else if(typeof(a[0]) === 'string')
return a[0].charCodeAt(a[1]+n);
return n==a[0].length?'\x00':a[0].charCodeAt(a[1]+n);
else
return new Uint8Array(a[0],a[1]+n)[0];
};
Expand Down

1 comment on commit e660085

@sviperll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart! I should have guessed how to do it myself :)

Please sign in to comment.