Commit e95dcc7c authored by Oliver Robson's avatar Oliver Robson

Implemented List / Tuple inputs

parent 47833b32
......@@ -32,7 +32,7 @@ function generateInputOptions() {
htmlStr += '<option value="float">Float</option>';
htmlStr += '<option value="stringnull">String, null terminated</option>';
htmlStr += '<option value="stringlen">String, with length</option>';
// htmlStr += '<option value="list">List</option>';
htmlStr += '<option value="list">List / Tuple</option>';
// htmlStr += '<option value="dict">Dictionary</option>';
htmlStr += '</select>';
htmlStr += '</div>';
......@@ -148,6 +148,13 @@ function generateCode() {
// Cast input arguments to appropriate types
for (var index=0; index < formDict['inputs'].length; index++) {
var argName;
if (numInputs <= MAX_DISCRETE_ARGS) {
argName = formDict['inputs'][index]['name'];
} else {
argName = 'args['+index+']';
}
var mpType, mpObjGet;
switch(formDict['inputs'][index]['type']) {
case 'bool':
......@@ -170,19 +177,26 @@ function generateCode() {
mpType = 'const char*';
mpObjGet = 'mp_obj_str_get_data';
break;
case 'list':
mpType = null;
mpObjGet = INDENT+'mp_obj_t *'+argName+' = NULL;\n';
mpObjGet += INDENT+'size_t '+argName+'_len = 0;\n';
mpObjGet += INDENT+'mp_obj_get_array('+argName+'_arg, &'+argName+'_len, &'+argName+');\n';
mpObjGet += INDENT+'mp_int_t '+argName+'_item_1 = mp_obj_get_int('+argName+'[0]);\n';
mpObjGet += INDENT+'mp_float_t '+argName+'_item_2 = mp_obj_get_float('+argName+'[1]);\n';
mpObjGet += INDENT+'const char* '+argName+'_item_3 = mp_obj_str_get_str('+argName+'[2]);\n';
if (index+1 < formDict['inputs'].length) {
mpObjGet += '\n';
}
break;
default:
mpType = 'mp_TODO_t';
mpObjGet = 'mp_obj_get_TODO';
}
var argName;
if (numInputs <= MAX_DISCRETE_ARGS) {
argName = formDict['inputs'][index]['name'];
} else {
argName = 'args['+index+']';
}
if (formDict['inputs'][index]['type'] == 'stringlen') {
if (mpType == null) {
outputCode += mpObjGet;
} else if (formDict['inputs'][index]['type'] == 'stringlen') {
outputCode += INDENT+'size_t '+argName+'_len;\n';
outputCode += INDENT+mpType+' '+formDict['inputs'][index]['name']+' = ';
outputCode += mpObjGet+'('+argName+'_obj, &'+argName+'_len);\n';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment