summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-22 00:57:28 +0800
committerruki <[email protected]>2020-12-22 00:57:28 +0800
commit0734881144db86eaf8a7dce17f32bdc5bccc7346 (patch)
treebaf88289ed0f31f9a5cd35cc8828b8d492fb85b0
parent03ea42dd480b1397394c2363a61b09f438498283 (diff)
fix repl history
-rw-r--r--xmake/core/cache/globalcache.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua11
2 files changed, 6 insertions, 7 deletions
diff --git a/xmake/core/cache/globalcache.lua b/xmake/core/cache/globalcache.lua
index fbed27408..a18b36ccf 100644
--- a/xmake/core/cache/globalcache.lua
+++ b/xmake/core/cache/globalcache.lua
@@ -58,7 +58,7 @@ end
-- save cache
function _instance:save()
- local ok, errors = io.save(path.join(config.cachedir(), self:name()), self._DATA)
+ local ok, errors = io.save(path.join(global.cachedir(), self:name()), self._DATA)
if not ok then
os.raise(errors)
end
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index 65e85fabe..c8a44d266 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -82,7 +82,7 @@ function sandbox_core_sandbox.interactive()
readline.clear_history()
-- load history
- replhistory = globalcache.get("history", "replhistory") or {}
+ replhistory = table.wrap(globalcache.get("history", "replhistory"))
for _, ln in ipairs(replhistory) do
readline.add_history(ln)
end
@@ -109,13 +109,12 @@ function sandbox_core_sandbox.interactive()
-- save to history
local entries = readline.history_list()
if #entries > #replhistory then
- local historylines = globalcache.get("history", "replhistory") or {}
for i = #replhistory + 1, #entries do
- if #historylines > 64 then
- table.remove(historylines, 1)
+ if #replhistory > 64 then
+ table.remove(replhistory, 1)
end
- table.insert(historylines, entries[i].line)
- globalcache.set("history", "replhistory", historylines)
+ table.insert(replhistory, entries[i].line)
+ globalcache.set("history", "replhistory", replhistory)
end
globalcache.save("history")
end