summaryrefslogtreecommitdiff
path: root/src/loslib.js
diff options
context:
space:
mode:
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) {