1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00
anselme/stdlib/persist.lua
Étienne Reuh Fildadut e71bff9562 Replace persistent variable system
Previous system linked the variable name with the saved value, meaning the variable could not be renamed or moved outside the global scope.

Instead we propose to store all persistent values in a global table, identifying each by a key. To still allow nice manipulation with identifiers, the alias syntax replace the persistent syntax for symbols - an aliases symbol will act as if a function call was used in place of the identifier when it appear.
2023-12-27 21:25:14 +01:00

32 lines
638 B
Lua

local ast = require("ast")
local persistent_manager = require("state.persistent_manager")
return {
{
"persist", "(key, default)",
function(state, key, default)
return persistent_manager:get(state, key, default)
end
},
{
"persist", "(key, default) = value",
function(state, key, default, value)
persistent_manager:set(state, key, value)
return ast.Nil:new()
end
},
{
"persist", "(key)",
function(state, key)
return persistent_manager:get(state, key)
end
},
{
"persist", "(key) = value",
function(state, key, value)
persistent_manager:set(state, key, value)
return ast.Nil:new()
end
},
}