Initial commit of Splash, a programming language aimed at kids. This was all done over the course of a 2 hour bus ride, and is currently only half working. Feel free to browse, keep checking back for a fully working build (scripts currently compile but do nothing in the browser)

This commit is contained in:
Ryan McGrath 2010-07-06 11:11:58 -04:00
commit 4e973d0b0f
11 changed files with 607 additions and 0 deletions

View file

@ -0,0 +1,47 @@
/* Simple linereader functionality for Node.js
*
* Allows you to iterate through a file line by line. "Nice" functionality.
*
* @Author: Ryan McGrath (ryan@venodesigns.net)
* @Requires: Nothing
*/
var fs = require("fs");
exports.reader = function(filename) {
var bufferSize = 8192, /* Generic for now */
currentPosition = 0,
buffer = "",
fd = fs.openSync(filename, "r");
function getBuffer(position) {
var res = fs.readSync(fd, bufferSize, position, "ascii");
buffer += res[0];
if(res[1] === 0) return -1;
return position + res[1];
}
currentPosition = getBuffer(0);
this.hasNextLine = function() {
while(buffer.indexOf("\n") === -1) {
currentPosition = getBuffer(currentPosition);
if(currentPosition === -1) return false;
}
if(buffer.indexOf("\n") > -1) return true;
return false;
};
this.getNextLine = function() {
var lineEnd = buffer.indexOf("\n"),
result = buffer.substring(0, lineEnd);
buffer = buffer.substring(result.length + 1, buffer.length);
return result;
};
return this;
};