Exemple #1
0
static int db_setlocal (lv_State *L) {
    int arg;
    lv_State *L1 = getthread(L, &arg);
    lv_Debug ar;
    if (!lv_getstack(L1, lvL_checkint(L, arg+1), &ar))  /* out of range? */
        return lvL_argerror(L, arg+1, "level out of range");
    lvL_checkany(L, arg+3);
    lv_settop(L, arg+3);
    lv_xmove(L, L1, 1);
    lv_pushstring(L, lv_setlocal(L1, &ar, lvL_checkint(L, arg+2)));
    return 1;
}
Exemple #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;
}
Exemple #3
0
static int db_getlocal (lv_State *L) {
    int arg;
    lv_State *L1 = getthread(L, &arg);
    lv_Debug ar;
    const char *name;
    if (!lv_getstack(L1, lvL_checkint(L, arg+1), &ar))  /* out of range? */
        return lvL_argerror(L, arg+1, "level out of range");
    name = lv_getlocal(L1, &ar, lvL_checkint(L, arg+2));
    if (name) {
        lv_xmove(L1, L, 1);
        lv_pushstring(L, name);
        lv_pushvalue(L, -2);
        return 2;
    }
    else {
        lv_pushnil(L);
        return 1;
    }
}
Exemple #4
0
static int setn (lv_State *L) {
    lv_clearFirstTableValue(L);
    lvL_checktype(L, 1, LV_TTABLE);
#ifndef lvL_setn
    lvL_setn(L, 1, lvL_checkint(L, 2));
#else
    lvL_error(L, LV_QL("setn") " is obsolete");
#endif
    lv_pushvalue(L, 1);
    return 1;
}
Exemple #5
0
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;
}