示例#1
0
static int db_setfenv (lv_State *L) {
    lvL_checktype(L, 2, LV_TTABLE);
    lv_settop(L, 2);
    if (lv_setfenv(L, 1) == 0)
        lvL_error(L, LV_QL("setfenv")
                  " cannot change environment of given object");
    return 1;
}
示例#2
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;
}
示例#3
0
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;
}
示例#4
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;
}
示例#5
0
static int db_debug (lv_State *L) {
    for (;;) {
        char buffer[250];
        fputs("lv_debug> ", stderr);
        if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
            strcmp(buffer, "cont\n") == 0)
            return 0;
        if (lvL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
            lv_pcall(L, 0, 0, 0)) {
            fputs(lv_tostring(L, -1), stderr);
            fputs("\n", stderr);
        }
        lv_settop(L, 0);  /* remove eventual returns */
    }
}
示例#6
0
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;
}
示例#7
0
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;
}