['symbol'] = {
['get_value'] = function(task, args)
local symbol = task:get_symbol(args[1])
- if args[2] and symbol then
- if args[2] == 'options' then
- -- concat options tables to avoid table representation strings produced by implicit conversion
- return fun.map(function(r) return table.concat(r[args[2]], ', ') end, symbol), 'string_list'
- elseif args[2] == 'score' then
- -- only userdata_list seems to work for scores
- return fun.map(function(r) return r[args[2]] end, symbol), 'userdata_list'
- else
- return fun.map(function(r) return r[args[2]] end, symbol), 'string_list'
- end
+ if symbol then
+ return symbol[1],'table'
end
- return symbol,'table_list'
end,
- ['description'] = [[Get specific symbol. The first argument must be the symbol name. If no second argument is specified, returns a list of symbol tables. Otherwise the second argument specifies the attribute which is returned as list (`options`, `score` or `group`)]],
- ['args_schema'] = {ts.string, ts.one_of{'options','score','group'}:is_optional()}
+ ['description'] = [[Get specific symbol. The first argument must be the symbol name. Returns the symbol table. See task:get_symbol()]],
+ ['args_schema'] = {ts.string}
},
}
['args_schema'] = {(ts.number + ts.string / tonumber),
(ts.number + ts.string / tonumber):is_optional()}
},
- -- Returns the string with all non ascii chars replaced
+ -- Returns the string(s) with all non ascii chars replaced
['to_ascii'] = {
['types'] = {
['string'] = true,
+ ['list'] = true,
},
['map_type'] = 'string',
- ['process'] = function(inp, _)
- return string.gsub(inp, '[\128-\255]', '?'), 'string'
+ ['process'] = function(inp, _, args)
+ if type(inp) == 'table' then
+ return fun.map( function(s) return string.gsub(tostring(s), '[\128-\255]', args[1] or '?') end , inp), 'string_list'
+ else
+ return string.gsub(tostring(inp), '[\128-\255]', '?'), 'string'
+ end
+
end,
- ['description'] = 'Returns the string with all non-ascii bytes replaced with `?`',
+ ['description'] = 'Returns the string with all non-ascii bytes replaced with the character given as second argument or `?`',
+ ['args_schema'] = {ts.string:is_optional()}
},
}
-- process selector expressions in the message
message = string.gsub(message, '(${(.-)})', process_message_selectors)
task:set_pre_result(act, message, N, nil, nil, flags)
-
else
task:set_pre_result(act, nil, N, nil, nil, flags)
end