diff --git a/clite/commands.js b/clite/commands.js index 164f829..dfd01ba 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -2354,18 +2354,14 @@ Options: }); if (window.location.protocol == 'file:') -clite.commands.load('exp',function(args,env,io) { - var stdio = io.include('stdio'); - var stdlib = io.include('stdlib'); +clite.commands.load('exp',` +var stdio = io.include('stdio'); - function main(argc,argv) { - stdio.printf('%d %d %d\n',stdlib.getuid(),stdlib.getgid(),io.pid); - - return 0; - } - - return main(args.length,args); -}); +function main(argc,argv) { + stdio.printf('hello world\\n'); + return 0; +} +`); // insert commands above this line } diff --git a/clite/core.js b/clite/core.js index 2d40af3..a7f50e5 100644 --- a/clite/core.js +++ b/clite/core.js @@ -345,7 +345,11 @@ cat /etc/greeting if (!f) return; f.mode = clite.lib.modestr('-rwxr-xr-x'); - f.data.content = fn; + if (typeof fn === 'string') { + f.data.content = new Function('args','env','io',fn+';return main(args.length,args);'); + }else{ + f.data.content = fn; + } if (typeof suid === 'boolean' && suid == true) f.mode |= clite.io.modes.S_ISUID; if (typeof sgid === 'boolean' && sgid == true) @@ -355,7 +359,11 @@ cat /etc/greeting if (!f) return; f.mode = clite.lib.modestr('-rw-rw-r--'); - f.data.content = 'function main'+fn.toString().substring(8); + if (typeof fn === 'string') { + f.data.content = fn; + }else{ + f.data.content = fn.toString().substring(8); + } } } @@ -1648,18 +1656,25 @@ clite.io = { } } } - if (typeof fd.node.data.content != 'string') - return false; - if (typeof data != 'string') - return false; - if (fd.pos + data.length >= fd.node.data.content.length) { - fd.node.data.content = fd.node.data.content.substring(0,fd.pos)+data; - fd.pos = fd.node.data.content.length; + if (typeof data === 'function') { + if (typeof fd.node.data.content !== 'string' && typeof fd.node.data.content !== 'function') + return false; + fd.node.data.content = data; + fd.pos = 0; }else{ - var b = fd.node.data.content.substring(0,fd.pos); - var e = fd.node.data.content.substring(fd.pos+data.length); - fd.node.data.content = b+data+e; - fd.pos += data.length; + if (typeof fd.node.data.content != 'string') + return false; + if (typeof data != 'string') + return false; + if (fd.pos + data.length >= fd.node.data.content.length) { + fd.node.data.content = fd.node.data.content.substring(0,fd.pos)+data; + fd.pos = fd.node.data.content.length; + }else{ + var b = fd.node.data.content.substring(0,fd.pos); + var e = fd.node.data.content.substring(fd.pos+data.length); + fd.node.data.content = b+data+e; + fd.pos += data.length; + } } fd.node.time.modify = clite.time.sec(); clite.vfs.saveFile(fd.path);