From 5894c5279ca8fc5757eb697bfd901889a4b9e065 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 10 May 2017 15:43:55 +0800 Subject: get_history_state -> history_list --- core/src/xmake/machine.c | 12 +-- core/src/xmake/makefile | 2 +- core/src/xmake/readline/get_history_state.c | 92 ---------------------- core/src/xmake/readline/history_list.c | 72 +++++++++++++++++ xmake/core/sandbox/modules/import/lib/readline.lua | 2 +- xmake/plugins/lua/xmake.lua | 2 +- 6 files changed, 81 insertions(+), 101 deletions(-) delete mode 100644 core/src/xmake/readline/get_history_state.c create mode 100644 core/src/xmake/readline/history_list.c diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 50da4ea7c..4001af365 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -106,7 +106,7 @@ tb_int_t xm_sandbox_interactive(lua_State* lua); #ifdef XM_CONFIG_API_HAVE_READLINE // the readline functions tb_int_t xm_readline_readline(lua_State* lua); -tb_int_t xm_readline_get_history_state(lua_State* lua); +tb_int_t xm_readline_history_list(lua_State* lua); tb_int_t xm_readline_add_history(lua_State* lua); tb_int_t xm_readline_clear_history(lua_State* lua); #endif @@ -185,11 +185,11 @@ static luaL_Reg const g_sandbox_functions[] = // the readline functions static luaL_Reg const g_readline_functions[] = { - { "readline", xm_readline_readline } -, { "get_history_state", xm_readline_get_history_state } -, { "add_history", xm_readline_add_history } -, { "clear_history", xm_readline_clear_history } -, { tb_null, tb_null } + { "readline", xm_readline_readline } +, { "history_list", xm_readline_history_list } +, { "add_history", xm_readline_add_history } +, { "clear_history", xm_readline_clear_history} +, { tb_null, tb_null } }; #endif diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 7f800d2d7..0b9770bf6 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -51,7 +51,7 @@ xmake_C_FILES += \ process/close \ sandbox/interactive \ readline/readline \ - readline/get_history_state \ + readline/history_list \ readline/add_history \ readline/clear_history diff --git a/core/src/xmake/readline/get_history_state.c b/core/src/xmake/readline/get_history_state.c deleted file mode 100644 index 184f0e9fc..000000000 --- a/core/src/xmake/readline/get_history_state.c +++ /dev/null @@ -1,92 +0,0 @@ -/*!The Make-like Build Utility based on Lua - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright (C) 2015 - 2017, TBOOX Open Source Group. - * - * @author TitanSnow - * @file get_history_state.c - * - */ - -/* ////////////////////////////////////////////////////////////////////////////////////// - * trace - */ -#define TB_TRACE_MODULE_NAME "get_history_state" -#define TB_TRACE_MODULE_DEBUG (0) - -/* ////////////////////////////////////////////////////////////////////////////////////// - * includes - */ -#include "prefix.h" - -#ifdef XM_CONFIG_API_HAVE_READLINE - -/* ////////////////////////////////////////////////////////////////////////////////////// - * implementation - */ - -// get_history_state wrapper -tb_int_t xm_readline_get_history_state(lua_State* lua) -{ - // check - tb_assert_and_check_return_val(lua, 0); - - // HISTORY_STATE table - lua_newtable(lua); - HISTORY_STATE *hs = history_get_history_state(); - // field offset - lua_pushstring(lua, "offset"); - lua_pushinteger(lua, hs -> offset); - lua_settable(lua, -3); - // field length - lua_pushstring(lua, "length"); - lua_pushinteger(lua, hs -> length); - lua_settable(lua, -3); - // field size - lua_pushstring(lua, "size"); - lua_pushinteger(lua, hs -> size); - lua_settable(lua, -3); - // field flags - lua_pushstring(lua, "flags"); - lua_pushinteger(lua, hs -> flags); - lua_settable(lua, -3); - // field entries - lua_pushstring(lua, "entries"); - lua_newtable(lua); - for (HIST_ENTRY **p = hs -> entries; *p; ++p) - { - lua_newtable(lua); - // field line - lua_pushstring(lua, "line"); - lua_pushstring(lua, (*p) -> line); - lua_settable(lua, -3); - // field timestamp - lua_pushstring(lua, "timestamp"); - lua_pushstring(lua, (*p) -> timestamp); - lua_settable(lua, -3); - - // set back - lua_rawseti(lua, -2, p - hs -> entries + 1); - } - lua_settable(lua, -3); - - // ok - return 1; -} - -#endif diff --git a/core/src/xmake/readline/history_list.c b/core/src/xmake/readline/history_list.c new file mode 100644 index 000000000..68597b945 --- /dev/null +++ b/core/src/xmake/readline/history_list.c @@ -0,0 +1,72 @@ +/*!The Make-like Build Utility based on Lua + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015 - 2017, TBOOX Open Source Group. + * + * @author TitanSnow + * @file history_list.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "history_list" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +#ifdef XM_CONFIG_API_HAVE_READLINE + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +// history_list wrapper +tb_int_t xm_readline_history_list(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // history list + lua_newtable(lua); + tb_int_t i = 1; + for (HIST_ENTRY **p = history_list(); *p; ++p, ++i) + { + lua_newtable(lua); + // field line + lua_pushstring(lua, "line"); + lua_pushstring(lua, (*p) -> line); + lua_settable(lua, -3); + // field timestamp + lua_pushstring(lua, "timestamp"); + lua_pushstring(lua, (*p) -> timestamp); + lua_settable(lua, -3); + + // set back + lua_rawseti(lua, -2, i); + } + + // ok + return 1; +} + +#endif diff --git a/xmake/core/sandbox/modules/import/lib/readline.lua b/xmake/core/sandbox/modules/import/lib/readline.lua index d96381413..b392d806a 100644 --- a/xmake/core/sandbox/modules/import/lib/readline.lua +++ b/xmake/core/sandbox/modules/import/lib/readline.lua @@ -31,7 +31,7 @@ end -- inherit some builtin interfaces sandbox_readline.readline = readline.readline -sandbox_readline.get_history_state = readline.get_history_state +sandbox_readline.history_list = readline.history_list sandbox_readline.add_history = readline.add_history sandbox_readline.clear_history = readline.clear_history diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua index 269e1b944..efa044f4b 100644 --- a/xmake/plugins/lua/xmake.lua +++ b/xmake/plugins/lua/xmake.lua @@ -78,7 +78,7 @@ task("lua") if enable_readline then -- save to history - local entries = readline.get_history_state().entries + local entries = readline.history_list() if #entries > #replhistory then for i = #replhistory+1, #entries do history.save("replhistory", entries[i].line) -- cgit v1.3.1