Java Code Examples for org.luaj.vm2.Lua#LUA_MULTRET

The following examples show how to use org.luaj.vm2.Lua#LUA_MULTRET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
void retstat() {
/* stat -> RETURN explist */
      FuncState fs = this.fs;
      expdesc e = new expdesc();
      int first, nret; /* registers with returned values */
      if (block_follow(true) || this.t.token == ';')
          first = nret = 0; /* return no values */
      else {
          nret = this.explist(e); /* optional return values */
          if (hasmultret(e.k)) {
              fs.setmultret(e);
              if (e.k == VCALL && nret == 1) { /* tail call? */
                  LuaC.SET_OPCODE(fs.getcodePtr(e), Lua.OP_TAILCALL);
                  LuaC._assert(Lua.GETARG_A(fs.getcode(e)) == fs.nactvar);
              }
              first = fs.nactvar;
              nret = Lua.LUA_MULTRET; /* return all values */
          } else {
              if (nret == 1) /* only one single value? */
                  first = fs.exp2anyreg(e);
              else {
                  fs.exp2nextreg(e); /* values must go to the `stack' */
                  first = fs.nactvar; /* return all `active' values */
                  LuaC._assert(nret == fs.freereg - first);
              }
          }
      }
      fs.ret(first, nret);
      testnext(';');  /* skip optional semicolon */
  }
 
Example 2
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
void retstat() {
	/* stat -> RETURN explist */
	FuncState fs = this.fs;
	expdesc e = new expdesc();
	int first, nret; /* registers with returned values */
	if (block_follow(true) || this.t.token == ';')
		first = nret = 0; /* return no values */
	else {
		nret = this.explist(e); /* optional return values */
		if (hasmultret(e.k)) {
			fs.setmultret(e);
			if (e.k == VCALL && nret == 1) { /* tail call? */
				SET_OPCODE(fs.getcodePtr(e), Lua.OP_TAILCALL);
				_assert (Lua.GETARG_A(fs.getcode(e)) == fs.nactvar);
			}
			first = fs.nactvar;
			nret = Lua.LUA_MULTRET; /* return all values */
		} else {
			if (nret == 1) /* only one single value? */
				first = fs.exp2anyreg(e);
			else {
				fs.exp2nextreg(e); /* values must go to the `stack' */
				first = fs.nactvar; /* return all `active' values */
				_assert (nret == fs.freereg - first);
			}
		}
	}
	fs.ret(first, nret);
	testnext(';');  /* skip optional semicolon */
}
 
Example 3
Source File: LexState.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
void retstat() {
	/* stat -> RETURN explist */
	FuncState fs = this.fs;
	expdesc e = new expdesc();
	int first, nret; /* registers with returned values */
	if (block_follow(true) || this.t.token == ';')
		first = nret = 0; /* return no values */
	else {
		nret = this.explist(e); /* optional return values */
		if (hasmultret(e.k)) {
			fs.setmultret(e);
			if (e.k == VCALL && nret == 1) { /* tail call? */
				SET_OPCODE(fs.getcodePtr(e), Lua.OP_TAILCALL);
				_assert (Lua.GETARG_A(fs.getcode(e)) == fs.nactvar);
			}
			first = fs.nactvar;
			nret = Lua.LUA_MULTRET; /* return all values */
		} else {
			if (nret == 1) /* only one single value? */
				first = fs.exp2anyreg(e);
			else {
				fs.exp2nextreg(e); /* values must go to the `stack' */
				first = fs.nactvar; /* return all `active' values */
				_assert (nret == fs.freereg - first);
			}
		}
	}
	fs.ret(first, nret);
	testnext(';');  /* skip optional semicolon */
}
 
Example 4
Source File: LexState.java    From luaj with MIT License 5 votes vote down vote up
void retstat() {
	/* stat -> RETURN explist */
	FuncState fs = this.fs;
	expdesc e = new expdesc();
	int first, nret; /* registers with returned values */
	if (block_follow(true) || this.t.token == ';')
		first = nret = 0; /* return no values */
	else {
		nret = this.explist(e); /* optional return values */
		if (hasmultret(e.k)) {
			fs.setmultret(e);
			if (e.k == VCALL && nret == 1) { /* tail call? */
				SET_OPCODE(fs.getcodePtr(e), Lua.OP_TAILCALL);
				_assert (Lua.GETARG_A(fs.getcode(e)) == fs.nactvar);
			}
			first = fs.nactvar;
			nret = Lua.LUA_MULTRET; /* return all values */
		} else {
			if (nret == 1) /* only one single value? */
				first = fs.exp2anyreg(e);
			else {
				fs.exp2nextreg(e); /* values must go to the `stack' */
				first = fs.nactvar; /* return all `active' values */
				_assert (nret == fs.freereg - first);
			}
		}
	}
	fs.ret(first, nret);
	testnext(';');  /* skip optional semicolon */
}
 
Example 5
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
void funcargs(expdesc f, int line) {
    FuncState fs = this.fs;
    expdesc args = new expdesc();
    int base, nparams;
    switch (this.t.token) {
        case '(': { /* funcargs -> `(' [ explist1 ] `)' */
            this.next();
            if (this.t.token == ')') /* arg list is empty? */
                args.k = VVOID;
            else {
                this.explist(args);
                fs.setmultret(args);
            }
            this.check_match(')', '(', line);
            break;
        }
        case '{': { /* funcargs -> constructor */
            this.constructor(args);
            break;
        }
        case TK_STRING: { /* funcargs -> STRING */
            this.codestring(args, this.t.seminfo.ts);
            this.next(); /* must use `seminfo' before `next' */
            break;
        }
        default: {
            this.syntaxerror("function arguments expected");
            return;
        }
    }
    LuaC._assert(f.k == VNONRELOC);
    base = f.u.info; /* base register for call */
    if (hasmultret(args.k))
        nparams = Lua.LUA_MULTRET; /* open call */
    else {
        if (args.k != VVOID)
            fs.exp2nextreg(args); /* close last argument */
        nparams = fs.freereg - (base + 1);
    }
    f.init(VCALL, fs.codeABC(Lua.OP_CALL, base, nparams + 1, 2));
    fs.fixline(line);
    fs.freereg = (short) (base + 1);  /* call remove function and arguments and leaves
			 * (unless changed) one result */
}
 
Example 6
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
void funcargs(expdesc f, int line) {
	FuncState fs = this.fs;
	expdesc args = new expdesc();
	int base, nparams;
	switch (this.t.token) {
	case '(': { /* funcargs -> `(' [ explist1 ] `)' */
		this.next();
		if (this.t.token == ')') /* arg list is empty? */
			args.k = VVOID;
		else {
			this.explist(args);
			fs.setmultret(args);
		}
		this.check_match(')', '(', line);
		break;
	}
	case '{': { /* funcargs -> constructor */
		this.constructor(args);
		break;
	}
	case TK_STRING: { /* funcargs -> STRING */
		this.codestring(args, this.t.seminfo.ts);
		this.next(); /* must use `seminfo' before `next' */
		break;
	}
	default: {
		this.syntaxerror("function arguments expected");
		return;
	}
	}
	_assert (f.k == VNONRELOC);
	base = f.u.info; /* base register for call */
	if (hasmultret(args.k))
		nparams = Lua.LUA_MULTRET; /* open call */
	else {
		if (args.k != VVOID)
			fs.exp2nextreg(args); /* close last argument */
		nparams = fs.freereg - (base + 1);
	}
	f.init(VCALL, fs.codeABC(Lua.OP_CALL, base, nparams + 1, 2));
	fs.fixline(line);
	fs.freereg = (short)(base+1);  /* call remove function and arguments and leaves
						 * (unless changed) one result */
}
 
Example 7
Source File: LexState.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
void funcargs(expdesc f, int line) {
	FuncState fs = this.fs;
	expdesc args = new expdesc();
	int base, nparams;
	switch (this.t.token) {
	case '(': { /* funcargs -> `(' [ explist1 ] `)' */
		this.next();
		if (this.t.token == ')') /* arg list is empty? */
			args.k = VVOID;
		else {
			this.explist(args);
			fs.setmultret(args);
		}
		this.check_match(')', '(', line);
		break;
	}
	case '{': { /* funcargs -> constructor */
		this.constructor(args);
		break;
	}
	case TK_STRING: { /* funcargs -> STRING */
		this.codestring(args, this.t.seminfo.ts);
		this.next(); /* must use `seminfo' before `next' */
		break;
	}
	default: {
		this.syntaxerror("function arguments expected");
		return;
	}
	}
	_assert (f.k == VNONRELOC);
	base = f.u.info; /* base register for call */
	if (hasmultret(args.k))
		nparams = Lua.LUA_MULTRET; /* open call */
	else {
		if (args.k != VVOID)
			fs.exp2nextreg(args); /* close last argument */
		nparams = fs.freereg - (base + 1);
	}
	f.init(VCALL, fs.codeABC(Lua.OP_CALL, base, nparams + 1, 2));
	fs.fixline(line);
	fs.freereg = (short)(base+1);  /* call remove function and arguments and leaves
						 * (unless changed) one result */
}
 
Example 8
Source File: LexState.java    From luaj with MIT License 4 votes vote down vote up
void funcargs(expdesc f, int line) {
	FuncState fs = this.fs;
	expdesc args = new expdesc();
	int base, nparams;
	switch (this.t.token) {
	case '(': { /* funcargs -> `(' [ explist1 ] `)' */
		this.next();
		if (this.t.token == ')') /* arg list is empty? */
			args.k = VVOID;
		else {
			this.explist(args);
			fs.setmultret(args);
		}
		this.check_match(')', '(', line);
		break;
	}
	case '{': { /* funcargs -> constructor */
		this.constructor(args);
		break;
	}
	case TK_STRING: { /* funcargs -> STRING */
		this.codestring(args, this.t.seminfo.ts);
		this.next(); /* must use `seminfo' before `next' */
		break;
	}
	default: {
		this.syntaxerror("function arguments expected");
		return;
	}
	}
	_assert (f.k == VNONRELOC);
	base = f.u.info; /* base register for call */
	if (hasmultret(args.k))
		nparams = Lua.LUA_MULTRET; /* open call */
	else {
		if (args.k != VVOID)
			fs.exp2nextreg(args); /* close last argument */
		nparams = fs.freereg - (base + 1);
	}
	f.init(VCALL, fs.codeABC(Lua.OP_CALL, base, nparams + 1, 2));
	fs.fixline(line);
	fs.freereg = (short)(base+1);  /* call remove function and arguments and leaves
						 * (unless changed) one result */
}