osc: add support for osc typetag in widget's precision property (issue #137)

This commit is contained in:
jean-emmanuel 2018-01-26 11:05:39 +01:00
parent 99c8dcb856
commit 3e9a56e3e8
4 changed files with 14 additions and 7 deletions

View file

@ -38,11 +38,15 @@ var parseType = function(type){
}
var parseArg = function(arg,precision){
var parseArg = function(arg, precision){
if (arg==null) return null
switch (typeof arg) {
case 'number':
return {type: precision == 0 ? 'i' : 'f', value: parseFloat(arg.toFixed(precision))}
var typeTagMatch = typeof precision == 'string' ? precision.match(/[0-9]+([a-zA-Z]{1})/) : null,
typeTag = typeTagMatch === null ? precision == 0 ? 'i' : 'f' : typeTagMatch[1],
precisionValue = parseFloat(precision) || 0
return {type: typeTag, value: parseFloat(arg.toFixed(precisionValue))}
case 'boolean':
return {type: arg ? 'T' : 'F', value: arg}
case 'object':