diff options
| author | ruki <[email protected]> | 2017-05-10 20:59:21 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-10 20:59:21 +0800 |
| commit | 966876f494902efecb1ea475bade16cd96fe160c (patch) | |
| tree | 1f91f27feead302448faed74adc3b214275fe08a | |
| parent | 194980341bd177815feb13a529892519138b9cb0 (diff) | |
| parent | da6e4cce0e4c1736db0898d53c16ac8ca0441846 (diff) | |
Merge pull request #84 from TitanSnow/replhistory
replhistory
| -rw-r--r-- | .travis.yml | 23 | ||||
| -rw-r--r-- | appveyor.yml | 20 | ||||
| -rw-r--r-- | core/src/xmake/machine.c | 25 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 6 | ||||
| -rw-r--r-- | core/src/xmake/os/versioninfo.c | 39 | ||||
| -rw-r--r-- | core/src/xmake/readline/add_history.c | 63 | ||||
| -rw-r--r-- | core/src/xmake/readline/clear_history.c | 59 | ||||
| -rw-r--r-- | core/src/xmake/readline/history_list.c | 82 | ||||
| -rw-r--r-- | core/src/xmake/readline/prefix.h | 41 | ||||
| -rw-r--r-- | core/src/xmake/readline/readline.c | 68 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua | 27 |
11 files changed, 422 insertions, 31 deletions
diff --git a/.travis.yml b/.travis.yml index e4ddbb9d2..3048265a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,12 @@ -sudo: required +sudo: false language: C os: - linux - osx -install: - - cd .. - - cp -r xmake xmake4build - - cd xmake4build - - make build; sudo make install - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update --verbose; fi - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd --verbose; fi - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install rust --verbose; fi - script: - - cd ../xmake/core - - xmake -v - - sudo cp -v build/xmake /usr/local/share/xmake - - xmake --version - - xmake create test_project - - cd test_project - - xmake + - scripts/get.sh __local__ + - xmake lua versioninfo + - xmake -P core + - export XMAKE_PROGRAM_DIR=$PWD/xmake + - core/build/xmake lua versioninfo diff --git a/appveyor.yml b/appveyor.yml index 991564aa0..1d0dc4321 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -os: +os: - Visual Studio 2015 - Visual Studio 2017 @@ -6,16 +6,10 @@ platform: - Win32 - Win64 -before_build: - - ps: Invoke-WebRequest "https://github.com/tboox/xmake/releases/download/v2.1.2/xmake-v2.1.2.exe" -OutFile "xmake-installer.exe" - - cmd: xmake-installer.exe /S /D=C:\xmake - - cmd: PATH=%PATH%;C:\xmake - - cmd: xmake --version - - ps: cp -r -force xmake\* C:\xmake - - cmd: xmake --version - - cmd: dir C:\xmake - build_script: - - cmd: cd core - - cmd: if %platform%==Win64 xmake f -a x64 - - cmd: xmake -v + - ps: Invoke-Expression (Get-Content scripts\get.ps1 | Out-String) + - cmd: xmake lua versioninfo + - cmd: if %platform%==Win64 xmake f -a x64 -P core + - cmd: xmake -P core + - cmd: set XMAKE_PROGRAM_DIR=%cd%\xmake + - cmd: core\build\xmake lua versioninfo diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index b9977d92a..4001af365 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -103,6 +103,14 @@ tb_int_t xm_process_close(lua_State* lua); // the sandbox functions 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_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 + /* ////////////////////////////////////////////////////////////////////////////////////// * globals */ @@ -173,6 +181,18 @@ static luaL_Reg const g_sandbox_functions[] = , { tb_null, tb_null } }; +#ifdef XM_CONFIG_API_HAVE_READLINE +// the readline functions +static luaL_Reg const g_readline_functions[] = +{ + { "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 + /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ @@ -379,6 +399,11 @@ xm_machine_ref_t xm_machine_init() // bind sandbox functions luaL_register(impl->lua, "sandbox", g_sandbox_functions); +#ifdef XM_CONFIG_API_HAVE_READLINE + // bind readline functions + luaL_register(impl->lua, "readline", g_readline_functions); +#endif + // init host #if defined(TB_CONFIG_OS_WINDOWS) lua_pushstring(impl->lua, "windows"); diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 0d41f4439..0b9770bf6 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -49,7 +49,11 @@ xmake_C_FILES += \ process/wait \ process/waitlist \ process/close \ - sandbox/interactive + sandbox/interactive \ + readline/readline \ + readline/history_list \ + readline/add_history \ + readline/clear_history # flags diff --git a/core/src/xmake/os/versioninfo.c b/core/src/xmake/os/versioninfo.c index ea75049c3..cc8504a11 100644 --- a/core/src/xmake/os/versioninfo.c +++ b/core/src/xmake/os/versioninfo.c @@ -228,6 +228,45 @@ tb_int_t xm_os_versioninfo(lua_State* lua) // set back to table lua_settable(lua, -3); + lua_pushstring(lua, "host"); + // init host +#if defined(TB_CONFIG_OS_WINDOWS) + lua_pushstring(lua, "windows"); +#elif defined(TB_CONFIG_OS_MACOSX) + lua_pushstring(lua, "macosx"); +#elif defined(TB_CONFIG_OS_LINUX) + lua_pushstring(lua, "linux"); +#elif defined(TB_CONFIG_OS_IOS) + lua_pushstring(lua, "ios"); +#elif defined(TB_CONFIG_OS_ANDROID) + lua_pushstring(lua, "android"); +#elif defined(TB_CONFIG_OS_LIKE_UNIX) + lua_pushstring(lua, "unix"); +#else + lua_pushstring(lua, "unknown"); +#endif + lua_settable(lua, -3); + + lua_pushstring(lua, "arch"); + // init architecture +#if defined(TB_ARCH_x86) || defined(TB_CONFIG_OS_WINDOWS) + lua_pushstring(lua, "i386"); +#elif defined(TB_ARCH_x64) + lua_pushstring(lua, "x86_64"); +#else + lua_pushstring(lua, TB_ARCH_STRING); +#endif + lua_settable(lua, -3); + + lua_pushstring(lua, "nuldev"); + // init redirect to null +#if defined(TB_CONFIG_OS_WINDOWS) + lua_pushstring(lua, "nul"); +#else + lua_pushstring(lua, "/dev/null"); +#endif + lua_settable(lua, -3); + // ok return 1; } diff --git a/core/src/xmake/readline/add_history.c b/core/src/xmake/readline/add_history.c new file mode 100644 index 000000000..57f947d0c --- /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 + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "add_history" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +#ifdef XM_CONFIG_API_HAVE_READLINE + +/* ////////////////////////////////////////////////////////////////////////////////////// + * 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/core/src/xmake/readline/clear_history.c b/core/src/xmake/readline/clear_history.c new file mode 100644 index 000000000..7517e2e43 --- /dev/null +++ b/core/src/xmake/readline/clear_history.c @@ -0,0 +1,59 @@ +/*!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 clear_history.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "clear_history" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +#ifdef XM_CONFIG_API_HAVE_READLINE + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +// clear_history wrapper +tb_int_t xm_readline_clear_history(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // call clear_history + clear_history(); + + // pushnil + lua_pushnil(lua); + + // 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..3b0f8c0d3 --- /dev/null +++ b/core/src/xmake/readline/history_list.c @@ -0,0 +1,82 @@ +/*!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); +#ifdef TB_CONFIG_OS_MACOSX + for (tb_int_t i = 1; i <= history_length; ++i) + { + lua_newtable(lua); + // field line + lua_pushstring(lua, "line"); + lua_pushstring(lua, history_get(i) -> line); + lua_settable(lua, -3); + + // set back + lua_rawseti(lua, -2, i); + } +#else + 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); + + // set back + lua_rawseti(lua, -2, i); + } +#endif + + // ok + return 1; +} + +#endif diff --git a/core/src/xmake/readline/prefix.h b/core/src/xmake/readline/prefix.h new file mode 100644 index 000000000..626cde146 --- /dev/null +++ b/core/src/xmake/readline/prefix.h @@ -0,0 +1,41 @@ +/*!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 prefix.h + * + */ +#ifndef XM_READLINE_PREFIX_H +#define XM_READLINE_PREFIX_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "../prefix.h" +#ifdef XM_CONFIG_API_HAVE_READLINE +# include <stdio.h> // on some OS (like centos) required +# include <readline/readline.h> +# include <readline/history.h> +#endif + + +#endif + + diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c new file mode 100644 index 000000000..c52ff02aa --- /dev/null +++ b/core/src/xmake/readline/readline.c @@ -0,0 +1,68 @@ +/*!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 readline.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "readline" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +#ifdef XM_CONFIG_API_HAVE_READLINE + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +// readline wrapper +tb_int_t xm_readline_readline(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the prompt + tb_char_t const* prompt = tb_null; + if (tb_strcmp("nil", luaL_typename(lua, 1)) != 0) + prompt = luaL_checkstring(lua, 1); + + // call readline + tb_char_t const* line = readline(prompt); + if (line) + lua_pushstring(lua, line); + else + lua_pushnil(lua); + + // free it + tb_free((void*)line); + + // ok + return 1; +} + +#endif diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index 5e24ec832..6ffb6b4f1 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -28,6 +28,7 @@ local sandbox_core_sandbox = sandbox_core_sandbox or {} -- load modules local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") +local history = require("project/history") -- enter interactive mode function sandbox_core_sandbox.interactive() @@ -47,8 +48,34 @@ function sandbox_core_sandbox.interactive() -- bind sandbox environment -- setfenv(0, instance._PUBLIC) + local enable_readline = os.versioninfo().features.readline + local replhistory + if enable_readline then + -- clear history + readline.clear_history() + + -- load history + replhistory = history.load("replhistory") or {} + for _, ln in ipairs(replhistory) do + readline.add_history(ln) + end + end + -- enter interactive mode with this new sandbox sandbox.interactive(instance._PUBLIC) + + if enable_readline then + -- save to history + local entries = readline.history_list() + if #entries > #replhistory then + for i = #replhistory+1, #entries do + history.save("replhistory", entries[i].line) + end + end + + -- clear history + readline.clear_history() + end end -- return module |
