nomsu/lib/secrets.nom

35 lines
1.2 KiB
Plaintext

require "lib/core.nom"
macro block [with secrets %block] =: ".."
|local secrets = {}
|\(%block's "value") as lua\
macro block [with secrets as %secret_name %block] =: ".."
|local \%secret_name as value\ = {}
|\(%block's "value") as lua\
# Access the lua variable that should be within scope
macro [secrets] =: "secrets"
macro [secret %key, secret value of %key, secret value for %key] =:
if ((%key's "type") != "Var"):
error ".."
|Wrong type, expected Var, but got: \%key's "type"\
".."|secrets[\repr (%key's "value")\]
macro block [secret %key = %new_value] =:
lua block ".."
|if vars.key.type ~= "Var" then
| compiler:error("Assignment operation has the wrong type for the left hand side. "
| .."Expected Var, but got: "..vars.key.type)
|end
|if vars.new_value.type ~= "Thunk" then
| compiler:error("Assignment operation has the wrong type for the right hand side. "
| .."Expected Thunk, but got: "..vars.new_value.type.."\\nMaybe you used '=' instead of '=:'?")
|end
".."|do
| local ret
| \lua expr "compiler:tree_to_lua(vars.new_value.value)"\
| secrets[\repr (%key's "value")\] = ret
|end