Example #1
0
int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
  luaK_dischargevars(fs, e);
  if (e->k == VNONRELOC) {
    if (!hasjumps(e)) return e->u.info;  /* exp is already in a register */
    if (e->u.info >= fs->nlocvars) {  /* reg. is not a local? */
      exp2reg(fs, e, e->u.info);  /* put value on it */
      return e->u.info;
    }
  }
  luaK_exp2nextreg(fs, e);  /* default */
  return e->u.info;
}
Example #2
0
int str_split_ere(const char *str, size_t slen,
		const char *fmt, size_t flen, ...)
{
	va_list v;
	char *_str, *_fmt;
	const char *exp_s, *exp_e;
	int ignore_flag;
	char *reg;
	size_t str_off = 0;
	size_t off;
	char *sreq;
	size_t sreqsize;
	int ret = 0;

	if (!str || !slen || !fmt || !flen)
		return ret;

	_str = strndup(str, slen);
	if (!_str)
		return ret;
	_fmt = strndup(fmt, flen);
	if (!_fmt) {
		free(_str);
		return ret;
	}

	va_start(v, flen);
	/* supports %[regex..] and %*[regex..] */
	exp_s = fmt;
	while (str_off < flen && *exp_s) {
		exp_e = exp_end(fmt, flen, exp_s);
		if (!exp_e) {
			LOGE("invalid exp - failed to find the end of exp\n");
			goto out;
		}

		if (exp2reg(exp_s, exp_e, &ignore_flag, &reg) == -1) {
			LOGE("failed to translate exp to reg\n");
			goto out;
		}

		if (ignore_flag == 1) {
			sreq = NULL;
			sreqsize = 0;
		} else {
			sreq = va_arg(v, char *);
			sreqsize = va_arg(v, size_t);
		}

		if (reg_match(str + str_off, reg, sreq, sreqsize, &off) == -1) {
			LOGE("failed to match reg\n");
			free(reg);
			goto out;
		} else {
			if (ignore_flag == 0)
				ret++;
		}

		exp_s = exp_e;
		str_off += off;
		free(reg);
	}

out:
	va_end(v);
	free(_str);
	free(_fmt);
	return ret;
}
Example #3
0
void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
  luaK_dischargevars(fs, e);
  freeexp(fs, e);
  luaK_reserveregs(fs, 1);
  exp2reg(fs, e, fs->freereg - 1);
}