aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-11-25 15:39:08 -0800
committerAlon Zakai <azakai@mozilla.com>2010-11-25 15:39:08 -0800
commit66d539dbe657aef413d05cdd8e69ee9768a5cb37 (patch)
tree2b526ad02c7c603e3ecf5fdcb31a39c6126b5a69 /src/library.js
parentb5eea6060f32c1be666fd52ba8b337701f8723dc (diff)
improve lua test + fixes
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index e39d5a1e..6e41b547 100644
--- a/src/library.js
+++ b/src/library.js
@@ -11,6 +11,12 @@ var Library = {
__print__(Pointer_stringify(__formatString.apply(null, args)));
},
+ sprintf: function() {
+ var str = arguments[0];
+ var args = Array.prototype.slice.call(arguments, 1);
+ _strcpy(str, __formatString.apply(null, args)); // not terribly efficient
+ },
+
fflush: function(file) {
__print__(null);
},
@@ -96,6 +102,37 @@ var Library = {
return 0; // TODO
},
+ strtod: function(str, endptr) {
+ // XXX handles only whitespace + |[0-9]+(.[0.9]+)?|, no e+
+ while (_isspace(str)) str++;
+ var chr;
+ var ret = 0;
+ while(1) {
+ chr = IHEAP[str];
+ if (!_isdigit(chr)) break;
+ ret = ret*10 + chr - '0'.charCodeAt(0);
+ str++;
+ }
+ if (IHEAP[str] == '.'.charCodeAt(0)) {
+ str++;
+ var mul=1/10;
+ while(1) {
+ chr = IHEAP[str];
+ if (!_isdigit(chr)) break;
+ ret += mul*(chr - '0'.charCodeAt(0));
+ mul /= 10;
+ str++;
+ }
+ }
+ if (endptr) {
+ IHEAP[endptr] = str;
+#if SAFE_HEAP
+ SAFE_HEAP_ACCESS(endptr, null, true);
+#endif
+ }
+ return ret;
+ },
+
// string.h
strspn: function(pstr, pset) {