Beispiel #1
0
static int db_errorfb (lv_State *L) {
    int level;
    int firstpart = 1;  /* still before eventual `...' */
    int arg;
    lv_State *L1 = getthread(L, &arg);
    lv_Debug ar;
    if (lv_isnumber(L, arg+2)) {
        level = (int)lv_tointeger(L, arg+2);
        lv_pop(L, 1);
    }
    else
        level = (L == L1) ? 1 : 0;  /* level 0 may be this own function */
    if (lv_gettop(L) == arg)
        lv_pushliteral(L, "");
    else if (!lv_isstring(L, arg+1)) return 1;  /* message is not a string */
    else lv_pushliteral(L, "\n");
    lv_pushliteral(L, "调用栈:");
    while (lv_getstack(L1, level++, &ar)) {
        if (level > LEVELS1 && firstpart) {
            /* no more than `LEVELS2' more levels? */
            if (!lv_getstack(L1, level+LEVELS2, &ar))
                level--;  /* keep going */
            else {
                lv_pushliteral(L, "\n\t...");  /* too many levels */
                while (lv_getstack(L1, level+LEVELS2, &ar))  /* find last levels */
                    level++;
            }
            firstpart = 0;
            continue;
        }
        lv_pushliteral(L, "\n\t");
        lv_getinfo(L1, "Snl", &ar);
        lv_pushfstring(L, "%s:", ar.source);
        if (ar.currentline > 0)
            lv_pushfstring(L, "%d:", ar.currentline);
        if (*ar.namewhat != '\0')  /* is there a name? */
            lv_pushfstring(L, " in function " LV_QS, ar.name);
        else {
            if (*ar.what == 'm')  /* main? */
                lv_pushfstring(L, " in main chunk");
            else if (*ar.what == 'C' || *ar.what == 't')
                lv_pushliteral(L, " ?");  /* C function or tail call */
            else
                lv_pushfstring(L, " in function <%s:%d>",
                               ar.source, ar.linedefined);
        }
        lv_concat(L, lv_gettop(L) - arg);
    }
    lv_concat(L, lv_gettop(L) - arg);
    return 1;
}
Beispiel #2
0
static int tinsert (lv_State *L) {
    lv_clearFirstTableValue(L);
    int e = aux_getn(L, 1) + 1;  /* first empty element */
    int pos;  /* where to insert new element */
    switch (lv_gettop(L)) {
    case 2: {  /* called with only 2 arguments */
        pos = e;  /* insert new element at the end */
        break;
    }
    case 3: {
        int i;
        pos = lvL_checkint(L, 2);  /* 2nd argument is the position */
        if (pos > e) e = pos;  /* `grow' array if necessary */
        for (i = e; i > pos; i--) {  /* move up elements */
            lv_rawgeti(L, 1, i-1);
            lv_rawseti(L, 1, i);  /* t[i] = t[i-1] */
        }
        break;
    }
    default: {
        return lvL_error(L, "wrong number of arguments to " LV_QL("insert"));
    }
    }
    lvL_setn(L, 1, e);  /* new size */
    lv_rawseti(L, 1, pos);  /* t[pos] = v */
    return 0;
}