summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorTitanSnow <[email protected]>2017-05-10 15:43:55 +0800
committerTitanSnow <[email protected]>2017-05-10 15:43:55 +0800
commit5894c5279ca8fc5757eb697bfd901889a4b9e065 (patch)
treea6a09160696c968936ea2c63a3ff561fc37b3fa9 /core/src
parent067d960804f438b5759f6b094a929a94b20b4deb (diff)
get_history_state -> history_list
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/machine.c12
-rw-r--r--core/src/xmake/makefile2
-rw-r--r--core/src/xmake/readline/history_list.c (renamed from core/src/xmake/readline/get_history_state.c)36
3 files changed, 15 insertions, 35 deletions
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/history_list.c
index 184f0e9fc..68597b945 100644
--- a/core/src/xmake/readline/get_history_state.c
+++ b/core/src/xmake/readline/history_list.c
@@ -19,14 +19,14 @@
* Copyright (C) 2015 - 2017, TBOOX Open Source Group.
*
* @author TitanSnow
- * @file get_history_state.c
+ * @file history_list.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "get_history_state"
+#define TB_TRACE_MODULE_NAME "history_list"
#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -40,35 +40,16 @@
* implementation
*/
-// get_history_state wrapper
-tb_int_t xm_readline_get_history_state(lua_State* lua)
+// history_list wrapper
+tb_int_t xm_readline_history_list(lua_State* lua)
{
// check
tb_assert_and_check_return_val(lua, 0);
- // HISTORY_STATE table
+ // history list
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)
+ tb_int_t i = 1;
+ for (HIST_ENTRY **p = history_list(); *p; ++p, ++i)
{
lua_newtable(lua);
// field line
@@ -81,9 +62,8 @@ tb_int_t xm_readline_get_history_state(lua_State* lua)
lua_settable(lua, -3);
// set back
- lua_rawseti(lua, -2, p - hs -> entries + 1);
+ lua_rawseti(lua, -2, i);
}
- lua_settable(lua, -3);
// ok
return 1;