コード例 #1
0
ファイル: lVtablib.c プロジェクト: RoadsInFarAway/LuaViewSDK
static int tremove (lv_State *L) {
    lv_clearFirstTableValue(L);
    int e = aux_getn(L, 1);
    int pos = lvL_optint(L, 2, e);
    if (!(1 <= pos && pos <= e))  /* position is outside bounds? */
        return 0;  /* nothing to remove */
    lvL_setn(L, 1, e - 1);  /* t.n = n-1 */
    lv_rawgeti(L, 1, pos);  /* result = t[pos] */
    for ( ; pos<e; pos++) {
        lv_rawgeti(L, 1, pos+1);
        lv_rawseti(L, 1, pos);  /* t[pos] = t[pos+1] */
    }
    lv_pushnil(L);
    lv_rawseti(L, 1, e);  /* t[e] = nil */
    return 1;
}
コード例 #2
0
ファイル: lVtablib.c プロジェクト: RoadsInFarAway/LuaViewSDK
static int tconcat (lv_State *L) {
    lv_clearFirstTableValue(L);
    lvL_Buffer b;
    size_t lsep;
    int i, last;
    const char *sep = lvL_optlstring(L, 2, "", &lsep);
    lvL_checktype(L, 1, LV_TTABLE);
    i = lvL_optint(L, 3, 1);
    last = lvL_opt(L, lvL_checkint, 4, lvL_getn(L, 1));
    lvL_buffinit(L, &b);
    for (; i < last; i++) {
        addfield(L, &b, i);
        lvL_addlstring(&b, sep, lsep);
    }
    if (i == last)  /* add last value (if interval was not empty) */
        addfield(L, &b, i);
    lvL_pushresult(&b);
    return 1;
}
コード例 #3
0
ファイル: lVdblib.c プロジェクト: AnySoWhat/LuaViewSDK
static int db_sethook (lv_State *L) {
    int arg, mask, count;
    lv_Hook func;
    lv_State *L1 = getthread(L, &arg);
    if (lv_isnoneornil(L, arg+1)) {
        lv_settop(L, arg+1);
        func = NULL; mask = 0; count = 0;  /* turn off hooks */
    }
    else {
        const char *smask = lvL_checkstring(L, arg+2);
        lvL_checktype(L, arg+1, LV_TFUNCTION);
        count = lvL_optint(L, arg+3, 0);
        func = hookf; mask = makemask(smask, count);
    }
    gethooktable(L);
    lv_pushlightuserdata(L, L1);
    lv_pushvalue(L, arg+1);
    lv_rawset(L, -3);  /* set new hook */
    lv_pop(L, 1);  /* remove hook table */
    lv_sethook(L1, func, mask, count);  /* set hooks */
    return 0;
}
コード例 #4
0
ファイル: lVoslib.c プロジェクト: AnySoWhat/LuaViewSDK
static int os_exit (lv_State *L) {
  exit(lvL_optint(L, 1, EXIT_SUCCESS));
}