check feature readline before load/save replhistory
@@ -34,8 +34,11 @@ task("lua")
-- imports
import("core.base.option")
import("core.sandbox.sandbox")
+ 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,18 +61,22 @@ task("lua")
import("scripts." .. name).main(unpack(option.get("arguments") or {}))
end
else
+ local replhistory
+ if enable_readline then
-- clear history
readline.clear_history()
-- load history
- local replhistory = history.load("replhistory") or {}
+ replhistory = history.load("replhistory") or {}
for _, ln in ipairs(replhistory) do
readline.add_history(ln)
end
+ end
-- enter interactive mode
sandbox.interactive()
+ if enable_readline then
-- save to history
local entries = readline.get_history_state().entries
if #entries > #replhistory then
@@ -81,6 +88,7 @@ task("lua")
-- clear history
readline.clear_history()
end
+ end
end)
-- set menu
