From cfd6ac4b61f3d175725620895120b7480056bafd Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 13 Apr 2017 12:46:03 +1000 Subject: lua-cli: Add support for configurable prompts --- tests/manual-tests/lua-cli.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js index f93f306..0b5519b 100755 --- a/tests/manual-tests/lua-cli.js +++ b/tests/manual-tests/lua-cli.js @@ -8,11 +8,9 @@ const linit = require('../../src/linit.js'); const fs = require('fs'); const readlineSync = require('readline-sync'); -readlineSync.setDefaultOptions({ - prompt: '> ' -}); - const stdin = lua.to_luastring("=stdin"); +const _PROMPT = lua.to_luastring("_PROMPT"); +const _PROMPT2 = lua.to_luastring("_PROMPT2"); const L = lauxlib.luaL_newstate(); @@ -21,7 +19,11 @@ linit.luaL_openlibs(L); console.log(lua.FENGARI_COPYRIGHT); for (;;) { - let input = readlineSync.prompt(); + lapi.lua_getglobal(L, _PROMPT); + let input = readlineSync.prompt({ + prompt: lapi.lua_tojsstring(L, -1) || '> ' + }); + lapi.lua_pop(L, 1); if (input.length === 0) continue; @@ -41,9 +43,11 @@ for (;;) { while (status === lua.thread_status.LUA_ERRSYNTAX && lapi.lua_tojsstring(L, -1).endsWith("")) { /* continuation */ lapi.lua_pop(L, 1); + lapi.lua_getglobal(L, _PROMPT2); input += "\n" + readlineSync.prompt({ - prompt: '>> ' + prompt: lapi.lua_tojsstring(L, -1) || '>> ' }); + lapi.lua_pop(L, 1); let buffer = lua.to_luastring(input); status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin); } -- cgit v1.2.3-54-g00ecf