From 0f44fc860f5481893bfe46c9339be953533aef8b Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 10 May 2017 14:02:21 +0800 Subject: check feature readline before load/save replhistory --- xmake/plugins/lua/xmake.lua | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'xmake/plugins/lua/xmake.lua') diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua index bef62203b..269e1b944 100644 --- a/xmake/plugins/lua/xmake.lua +++ b/xmake/plugins/lua/xmake.lua @@ -34,8 +34,11 @@ task("lua") -- imports import("core.base.option") import("core.sandbox.sandbox") - import("core.project.history") - import("lib.readline") + local enable_readline = os.versioninfo().features.readline + if enable_readline then + import("core.project.history") + import("lib.readline") + end -- list all scripts? if option.get("list") then @@ -58,28 +61,33 @@ task("lua") import("scripts." .. name).main(unpack(option.get("arguments") or {})) end else - -- clear history - readline.clear_history() - - -- load history - local replhistory = history.load("replhistory") or {} - for _, ln in ipairs(replhistory) do - readline.add_history(ln) + 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 sandbox.interactive() - -- save to history - local entries = readline.get_history_state().entries - if #entries > #replhistory then - for i = #replhistory+1, #entries do - history.save("replhistory", entries[i].line) + if enable_readline then + -- save to history + local entries = readline.get_history_state().entries + if #entries > #replhistory then + for i = #replhistory+1, #entries do + history.save("replhistory", entries[i].line) + end end - end - -- clear history - readline.clear_history() + -- clear history + readline.clear_history() + end end end) -- cgit v1.3.1