@ady624 i know you have presence on your mind and fingers right now which is awesome! but i was running in to the need for a way to clear list[] variables and also seen others on the forum asking about how to clear list. i added these 3 lines of code to webcore-piston and if i do set variable listName[*CLEAR] it seems to clear the list[] variable without any secondary issues … that i can tell.
if (var.index == "*CLEAR") {
variable.v.clear()
} else {
any unexpected side effects i should be aware of? heres the full method for quick context:
private Map setVariable(rtData, name, value) {
def var = parseVariableName(name)
name = sanitizeVariableName(var.name)
if (!name) return [t: "error", v: "Invalid empty variable name"]
if (name.startsWith("@")) {
def variable = rtData.globalVars[name]
if (variable instanceof Map) {
//set global var
variable.v = cast(rtData, value, variable.t)
Map cache = rtData.gvCache ?: [:]
cache[name] = variable
rtData.gvCache = cache
return variable
}
} else {
def variable = rtData.localVars[var.name]
if (variable instanceof Map) {
//set value
if (variable.t.endsWith(']')) {
//we're dealing with a list
variable.v = (variable.v instanceof Map) ? variable.v : [:]
if (var.index == "*CLEAR") {
variable.v.clear()
} else {
Map indirectVar = getVariable(rtData, var.index)
//indirect variable addressing
if (indirectVar && (indirectVar.t != 'error')) {
var.index = cast(rtData, indirectVar.v, 'string', indirectVar.t)
}
variable.v[var.index] = cast(rtData, value, variable.t.replace('[]', ''))
}
} else {
variable.v = cast(rtData, value, variable.t)
}
if (!variable.f) {
def vars = state.vars
vars[name] = variable.v
state.vars = vars
atomicState.vars = vars
}
return variable
}
}
result = [t: 'error', v: 'Invalid variable']
}