예제 #1
0
static int db_setmetatable (lv_State *L) {
    int t = lv_type(L, 2);
    lvL_argcheck(L, t == LV_TNIL || t == LV_TTABLE, 2,
                 "nil or table expected");
    lv_settop(L, 2);
    lv_pushboolean(L, lv_setmetatable(L, 1));
    return 1;
}
예제 #2
0
static int maxn (lv_State *L) {
    lv_clearFirstTableValue(L);
    lv_Number max = 0;
    lvL_checktype(L, 1, LV_TTABLE);
    lv_pushnil(L);  /* first key */
    while (lv_next(L, 1)) {
        lv_pop(L, 1);  /* remove value */
        if (lv_type(L, -1) == LV_TNUMBER) {
            lv_Number v = lv_tonumber(L, -1);
            if (v > max) max = v;
        }
    }
    lv_pushnumber(L, max);
    return 1;
}