コード例 #1
0
ファイル: lVtablib.c プロジェクト: RoadsInFarAway/LuaViewSDK
static int sort (lv_State *L) {
    lv_clearFirstTableValue(L);
    int n = aux_getn(L, 1);
    lvL_checkstack(L, 40, "");  /* assume array is smaller than 2^40 */
    if (!lv_isnoneornil(L, 2))  /* is there a 2nd argument? */
        lvL_checktype(L, 2, LV_TFUNCTION);
    lv_settop(L, 2);  /* make sure there is two arguments */
    auxsort(L, 1, n);
    return 0;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: lVoslib.c プロジェクト: AnySoWhat/LuaViewSDK
static int os_time (lv_State *L) {
  time_t t;
  if (lv_isnoneornil(L, 1))  /* called without args? */
    t = time(NULL);  /* get current time */
  else {
    struct tm ts;
    lvL_checktype(L, 1, LV_TTABLE);
    lv_settop(L, 1);  /* make sure table is at the top */
    ts.tm_sec = getfield(L, "sec", 0);
    ts.tm_min = getfield(L, "min", 0);
    ts.tm_hour = getfield(L, "hour", 12);
    ts.tm_mday = getfield(L, "day", -1);
    ts.tm_mon = getfield(L, "month", -1) - 1;
    ts.tm_year = getfield(L, "year", -1) - 1900;
    ts.tm_isdst = getboolfield(L, "isdst");
    t = mktime(&ts);
  }
  if (t == (time_t)(-1))
    lv_pushnil(L);
  else
    lv_pushnumber(L, (lv_Number)t);
  return 1;
}