summaryrefslogtreecommitdiff
path: root/tests/manual-tests/lua-cli.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual-tests/lua-cli.js')
-rwxr-xr-xtests/manual-tests/lua-cli.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js
new file mode 100755
index 0000000..6c7801c
--- /dev/null
+++ b/tests/manual-tests/lua-cli.js
@@ -0,0 +1,33 @@
+#!/usr/bin/env node
+"use strict";
+
+const lua = require('../../src/lua.js');
+const lapi = require('../../src/lapi.js');
+const lauxlib = require('../../src/lauxlib.js');
+const linit = require('../../src/linit.js');
+const fs = require('fs');
+const readlineSync = require('readline-sync');
+
+readlineSync.setDefaultOptions({
+ prompt: '> '
+});
+
+const L = lauxlib.luaL_newstate();
+
+linit.luaL_openlibs(L);
+
+console.log(lua.FENGARI_COPYRIGHT);
+
+for (;;) {
+ let input = readlineSync.prompt();
+
+ if (input.length === 0)
+ continue;
+
+ let buffer = lua.to_luastring(input);
+ if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, lua.to_luastring("=stdin"))
+ || lapi.lua_pcall(L, 0, 0, 0)) {
+ lauxlib.lua_writestringerror(`${lapi.lua_tojsstring(L, -1)}\n`);
+ }
+ lapi.lua_settop(L, 0); /* remove eventual returns */
+}