Esempio n. 1
0
static int gfind (lua_State *L) {
  luaL_checkwstring(L, 1);
  luaL_checkwstring(L, 2);
  lua_settop(L, 2);
  lua_pushnumber(L, 0);
  lua_pushcclosure(L, gfind_aux, 3);
  return 1;
}
Esempio n. 2
0
static int wgmatch (lua_State *L) {
    luaL_checkwstring(L, 1);
    luaL_checkwstring(L, 2);
    lua_settop(L, 2);
    lua_pushinteger(L, 0);
    lua_pushcclosure(L, wgmatch_aux, 3);
    return 1;
}
Esempio n. 3
0
static int wstr_gsub (lua_State *L) {
    size_t srcl;
    const lua_WChar *src = luaL_checklwstring(L, 1, &srcl);
    const lua_WChar *p = luaL_checkwstring(L, 2);
    int max_s = luaL_optint(L, 4, srcl+1);
    int anchor = (*p == '^') ? (p++, 1) : 0;
    int n = 0;
    WMatchState ms;
    luaL_Buffer b;
    luaL_wbuffinit(L, &b);
    ms.L = L;
    ms.src_init = src;
    ms.src_end = src+srcl;
    while (n < max_s) {
        const lua_WChar *e;
        ms.level = 0;
        e = wmatch(&ms, src, p);
        if (e) {
            n++;
            wadd_value(&ms, &b, src, e);
        }
        if (e && e>src) /* non empty wmatch? */
            src = e;  /* skip it */
        else if (src < ms.src_end)
            luaL_addwchar(&b, *src++);
        else break;
        if (anchor) break;
    }
    luaL_addlwstring(&b, src, ms.src_end-src);
    luaL_pushresult(&b);
    lua_pushinteger(L, n);  /* number of substitutions */
    return 2;
}
Esempio n. 4
0
static int luaB_tonumber (lua_State *L) {
  int base = luaL_optint(L, 2, 10);
  if (base == 10) {  /* standard conversion */
    luaL_checkany(L, 1);
    if (lua_isnumber(L, 1)) {
      lua_pushnumber(L, lua_tonumber(L, 1));
      return 1;
    }
  }
  else if (lua_type(L, 1) == LUA_TWSTRING) {
    const lua_WChar *s1 = luaL_checkwstring(L, 1);
    lua_WChar *s2;
    unsigned long n;
    luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
    n = wcstoul(s1, &s2, base);
    if (s1 != s2) {  /* at least one valid digit? */
      while (iswspace(*s2)) s2++;  /* skip trailing spaces */
      if (*s2 == '\0') {  /* no invalid trailing characters? */
        lua_pushnumber(L, n);
        return 1;
      }
    }
  }
  else {
    const char *s1 = luaL_checkstring(L, 1);
    char *s2;
    unsigned long n;
    luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
    n = strtoul(s1, &s2, base);
    if (s1 != s2) {  /* at least one valid digit? */
      while (isspace((unsigned char)(*s2))) s2++;  /* skip trailing spaces */
      if (*s2 == '\0') {  /* no invalid trailing characters? */
        lua_pushnumber(L, (lua_Number)n);
        return 1;
      }
    }
  }
  lua_pushnil(L);  /* else not a number */
  return 1;
}
Esempio n. 5
0
static int str_gsub (lua_State *L) {
  size_t srcl;
  const lua_WChar *src = luaL_checklwstring(L, 1, &srcl);
  const lua_WChar *p = luaL_checkwstring(L, 2);
  int max_s = luaL_optint(L, 4, srcl+1);
  int anchor = (*p == '^') ? (p++, 1) : 0;
  int n = 0;
  MatchState ms;
  luaL_Buffer b;
  luaL_argcheck(L,
    lua_gettop(L) >= 3 && (lua_iswstring(L, 3) || lua_isfunction(L, 3)),
    3, "string or function expected");
  luaL_wbuffinit(L, &b);
  ms.L = L;
  ms.src_init = src;
  ms.src_end = src+srcl;
  while (n < max_s) {
    const lua_WChar *e;
    ms.level = 0;
    e = match(&ms, src, p);
    if (e) {
      n++;
      add_s(&ms, &b, src, e);
    }
    if (e && e>src) /* non empty match? */
      src = e;  /* skip it */
    else if (src < ms.src_end)
      luaL_putwchar(&b, *src++);
    else break;
    if (anchor) break;
  }
  luaL_addlwstring(&b, src, ms.src_end-src);
  luaL_pushresult(&b);
  lua_pushnumber(L, n);  /* number of substitutions */
  return 2;
}
Esempio n. 6
0
	static int set_domain(lua_State* L)
	{
		base::i18n::v2::set_domain(luaL_checkwstring(L, 1));
		return 0;
	}