diff options
| author | TitanSnow <[email protected]> | 2017-05-10 12:32:23 +0800 |
|---|---|---|
| committer | TitanSnow <[email protected]> | 2017-05-10 12:32:23 +0800 |
| commit | 1fe068e98cac89e96c2f42f3a4685ce267dd33b5 (patch) | |
| tree | 0158d2c574ecafc444a85436266384adf6352ea7 | |
| parent | b0807b28f1d1bf5fc93b692f58ec3bdd60f2a273 (diff) | |
add readline.add_history()
| -rw-r--r-- | core/src/xmake/machine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 3 | ||||
| -rw-r--r-- | core/src/xmake/readline/add_history.c | 63 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/readline.lua | 1 |
4 files changed, 68 insertions, 1 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index e31a75abf..5a8a7b4b8 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -107,6 +107,7 @@ tb_int_t xm_sandbox_interactive(lua_State* lua); // 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_add_history(lua_State* lua); #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -185,6 +186,7 @@ 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 } , { tb_null, tb_null } }; #endif diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 6150c564d..930f58df6 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -51,7 +51,8 @@ xmake_C_FILES += \ process/close \ sandbox/interactive \ readline/readline \ - readline/get_history_state + readline/get_history_state \ + readline/add_history # flags diff --git a/core/src/xmake/readline/add_history.c b/core/src/xmake/readline/add_history.c new file mode 100644 index 000000000..1b466ca6a --- /dev/null +++ b/core/src/xmake/readline/add_history.c @@ -0,0 +1,63 @@ +/*!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 add_history.c + * + */ + +#ifdef XM_CONFIG_API_HAVE_READLINE + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "add_history" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +// add_history wrapper +tb_int_t xm_readline_add_history(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get history + tb_char_t const* history = luaL_checkstring(lua, 1); + tb_check_return_val(history, 0); + + // call add_history + add_history(history); + + // pushnil + lua_pushnil(lua); + + // 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 15b51af76..02d183bc4 100644 --- a/xmake/core/sandbox/modules/import/lib/readline.lua +++ b/xmake/core/sandbox/modules/import/lib/readline.lua @@ -32,6 +32,7 @@ end -- inherit some builtin interfaces sandbox_readline.readline = readline.readline sandbox_readline.get_history_state = readline.get_history_state +sandbox_readline.add_history = readline.add_history -- return module return sandbox_readline |
