summaryrefslogtreecommitdiff
path: root/src/loslib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-28 15:57:31 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-28 15:57:31 +0200
commit30264bbc1998ab6640afdc31c348ca6167ca6191 (patch)
treed66080ac55ba07ace41b828652c5a6419e650b66 /src/loslib.js
parent5d4b124a2fd10e3c156a5cf440a901cff13bfadf (diff)
downloadfengari-30264bbc1998ab6640afdc31c348ca6167ca6191.tar.gz
fengari-30264bbc1998ab6640afdc31c348ca6167ca6191.tar.bz2
fengari-30264bbc1998ab6640afdc31c348ca6167ca6191.zip
os.execute
Diffstat (limited to 'src/loslib.js')
-rw-r--r--src/loslib.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/loslib.js b/src/loslib.js
index 1cc7d84..cb82bc3 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -95,9 +95,11 @@ if (typeof require === "function") {
let fs = false;
let tmp = false;
+ let child_process = false;
try {
fs = require('fs');
tmp = require('tmp');
+ child_process = require('child_process');
} catch (e) {}
if (fs && tmp) {
@@ -144,6 +146,37 @@ if (typeof require === "function") {
syslib.tmpname = os_tmpname;
}
+ if (child_process) {
+ const os_execute = function(L) {
+ let cmd = lauxlib.luaL_optstring(L, 1, null);
+ let out = false;
+ if (cmd !== null) {
+ try {
+ out = child_process.execSync(lua.to_jsstring(cmd));
+ } catch (e) {
+ return lauxlib.luaL_execresult(L, false, e);
+ }
+
+ // if (out) console.log(out);
+
+ return lauxlib.luaL_execresult(L, true);
+ } else {
+ try {
+ out = child_process.execSync(lua.to_jsstring(cmd));
+ lua.lua_pushboolean(L, 1);
+ } catch (e) {
+ lua.lua_pushboolean(L, 0);
+ }
+
+ // if (out) console.log(out);
+
+ return 1;
+ }
+ };
+
+ syslib.execute = os_execute;
+ }
+
}
const luaopen_os = function(L) {