diff options
| author | ruki <[email protected]> | 2020-03-24 22:35:14 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-03-24 09:31:24 +0800 |
| commit | 5fd9b5d24e354dfc0588a04d40b4e08ab0c430c9 (patch) | |
| tree | 3264528462d204878abfd690375c0624d9dbcfbe /core | |
| parent | 5218660a642fc31120c34d8ede2de093011c57db (diff) | |
improve interactive prompt
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/xmake/sandbox/interactive.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index a72e8df01..6ee010e24 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -48,12 +48,6 @@ * macros */ -// interactive prompt -#define LUA_PROMPT "> " - -// continuation prompt -#define LUA_PROMPT2 ">> " - // buffer size for prompt #define LUA_PROMPT_BUFSIZE 4096 @@ -185,11 +179,11 @@ static tb_size_t xm_sandbox_readline(tb_char_t* data, tb_size_t maxn, tb_char_t } // read and push input line -static tb_int_t xm_sandbox_pushline(lua_State* lua) +static tb_int_t xm_sandbox_pushline(lua_State* lua, tb_char_t const* prompt2) { // read line tb_char_t data[LUA_PROMPT_BUFSIZE]; - tb_size_t size = xm_sandbox_readline(data, sizeof(data), LUA_PROMPT2); + tb_size_t size = xm_sandbox_readline(data, sizeof(data), prompt2); if (size) { // split line '\0' @@ -213,10 +207,21 @@ static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) // clear stack lua_settop(lua, top); + // get prompt strings from arg1(sandbox_scope) + lua_pushstring(lua, "$interactive_prompt"); + lua_gettable(lua, 1); + tb_char_t const* prompt = lua_tostring(lua, -1); + lua_pop(lua, 1); + + lua_pushstring(lua, "$interactive_prompt2"); + lua_gettable(lua, 1); + tb_char_t const* prompt2 = lua_tostring(lua, -1); + lua_pop(lua, 1); + // read first line tb_int_t status; tb_char_t data[LUA_PROMPT_BUFSIZE]; - tb_size_t size = xm_sandbox_readline(data + 7, sizeof(data) - 7, LUA_PROMPT); + tb_size_t size = xm_sandbox_readline(data + 7, sizeof(data) - 7, prompt); if (size) { // split line '\0' @@ -254,7 +259,7 @@ static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) if (!xm_sandbox_incomplete(lua, status)) break; // get more input - if (!xm_sandbox_pushline(lua)) return -1; + if (!xm_sandbox_pushline(lua, prompt2)) return -1; // cancel multi-line input? if (!tb_strcmp(lua_tostring(lua, -1), "q")) |
