static int auxupvalue (lv_State *L, int get) { const char *name; int n = lvL_checkint(L, 2); lvL_checktype(L, 1, LV_TFUNCTION); if (lv_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from [L u a] */ name = get ? lv_getupvalue(L, 1, n) : lv_setupvalue(L, 1, n); if (name == NULL) return 0; lv_pushstring(L, name); lv_insert(L, -(get+1)); return get + 1; }
void interpret(int a[], int *np, int N) { char command[2]; char key[2]; int k; void *p; while (command[0] != 'q') { printf("\nInput command ->"); scanf("%1s", command); scanf("%1s", &key); k = (int)key[0]; switch (command[0]) { case 'i' : case 'I' : if (*np < N) { lv_insert(&k, a, np, sizeof(int), intcmp); printf("\n Successful Insert."); } else printf("\n Error : Table full."); break; case 'd' : case 'D' : if (lv_delete(&k, a, np, sizeof(int), intcmp) == NULL) printf("\n Error : Table empty or can't find."); else printf("\n Successful delete."); break; case 's' : case 'S' : if ((p = lv_search(&k, a, np, sizeof(int), intcmp)) == NULL) printf("\n Error : Can'f find that key"); else printf("\n Ok! find in %d th position", ((char*)p-(char*)a)/sizeof(int)); break; case 'f' : case 'F' : if ((p = lfv_search(&k, a, np, sizeof(int), intcmp)) == NULL) printf("\n Error : Can't find that key"); else printf("\n Ok ! find in %d th position & move front", ((char*)p-(char*)a)/sizeof(int)); break; case 'l' : case 'L' : li_list(a, *np); break; } printf(" n = %d", *np); } }