static void new_list(void) { int ret; int size = 8 ; int marks[8] = { 0,0,0,0,1,1,0,0 }; const char *options[] = { "Blue" , "Red" , "Green" , "Yellow" , "Black" , "White" , "Gray" , "Brown" } ; IupSetGlobal("PARENTDIALOG", "_MAIN_DIALOG_TEST_"); ret = IupListDialog(2,"IupListDialog Test",size,options,0,8,5,marks); IupSetGlobal("PARENTDIALOG", NULL); if (ret == -1) { printf("CANCEL\n"); } else { int i; char selection[80] = ""; printf("OK\n"); for(i = 0 ; i < size ; i++) { if(marks[i]) { char temp[10]; sprintf(temp,"%s\n",options[i]); strcat(selection,temp); } } printf(" Options (%s)\n", selection); } }
static int ListDialog(lua_State *L) { int type = luaL_checkint(L,1); int size = luaL_checkint(L,3); char** list = iuplua_checkstring_array(L, 4, size); int* marks = lua_isnoneornil(L, 8)? NULL: iuplua_checkint_array(L,8,0); int i, ret; if (!marks && type==2) luaL_error(L, "invalid marks, must not be nil."); if (marks && type==2 && size != iuplua_getn(L, 8)) luaL_error(L, "invalid number of elements in the marks."); ret = IupListDialog(type, luaL_checkstring(L, 2), size, list, luaL_checkint(L, 5), luaL_checkint(L, 6), luaL_checkint(L, 7), marks); if (marks && type==2 && ret!=-1) { for (i=0; i<size; i++) { lua_pushinteger(L, i+1); lua_pushinteger(L, marks[i]); lua_settable(L, 8); } } lua_pushinteger(L, ret); if (marks) free(marks); free(list); return 1; }
static void ListDialog(void) { lua_Object list_tbl = luaL_tablearg(4); lua_Object marks_tbl; int i, ret; char **list; int *marks = NULL; int type = luaL_check_int(1); char* title = luaL_check_string(2); int size = luaL_check_int(3); int opt = luaL_check_int(5); int max_col = luaL_check_int(6); int max_lin = luaL_check_int(7); marks_tbl = lua_getparam(8); if (!lua_isnil(marks_tbl)) { luaL_arg_check(lua_istable(marks_tbl), 8, "table expected"); marks = malloc(sizeof(int) * size); } if (!marks && type==2) lua_error("invalid marks, must not be nil."); list = malloc(sizeof(char *) * size); for (i = 0; i < size; i++) { lua_beginblock(); lua_pushobject(list_tbl); lua_pushnumber(i + 1); list[i] = lua_getstring(lua_gettable()); if (marks) { lua_pushobject(marks_tbl); lua_pushnumber(i + 1); marks[i] = (int) lua_getnumber(lua_gettable()); } lua_endblock(); } ret = IupListDialog(type, title, size, list, opt, max_col, max_lin, marks); if (marks && type==2 && ret!=-1) { for (i = 0; i < size; i++) { lua_beginblock(); lua_pushobject(marks_tbl); lua_pushnumber(i + 1); lua_pushnumber(marks[i]); lua_settable(); lua_endblock(); } } lua_pushnumber(ret); if (marks) free(marks); free(list); }