本文整理汇总了Java中org.luaj.vm2.Varargs.checkstring方法的典型用法代码示例。如果您正苦于以下问题:Java Varargs.checkstring方法的具体用法?Java Varargs.checkstring怎么用?Java Varargs.checkstring使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.luaj.vm2.Varargs
的用法示例。
在下文中一共展示了Varargs.checkstring方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
public Varargs invoke(Varargs args) {
LuaString name = args.checkstring(1);
InputStream is = null;
// get package path
LuaValue path = package_.get(_PATH);
if (!path.isstring())
return valueOf("package.path is not a string");
// get the searchpath function.
Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));
// Did we get a result?
if (!v.isstring(1))
return v.arg(2).tostring();
LuaString filename = v.arg1().strvalue();
// Try to load the file.
v = globals.loadfile(filename.tojstring());
if (v.arg1().isfunction())
return LuaValue.varargsOf(v.arg1(), filename);
// report error
return varargsOf(NIL, valueOf("'" + filename + "': " + v.arg(2).tojstring()));
}
示例2: byte_
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
/**
* string.byte (s [, i [, j]])
*
* Returns the internal numerical codes of the
* characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the
* default value for j is i.
*
* Note that numerical codes are not necessarily portable across platforms.
*
* @param args the calling args
*/
static Varargs byte_(Varargs args) {
LuaString s = args.checkstring(1);
int l = s.m_length;
int posi = posrelat(args.optint(2, 1), l);
int pose = posrelat(args.optint(3, posi), l);
int n, i;
if (posi <= 0) posi = 1;
if (pose > l) pose = l;
if (posi > pose) return NONE; /* empty interval; return no values */
n = (int) (pose - posi + 1);
if (posi + n <= pose) /* overflow? */
error("string slice too long");
LuaValue[] v = new LuaValue[n];
for (i = 0; i < n; i++)
v[i] = valueOf(s.luaByte(posi + i - 1));
return varargsOf(v);
}
示例3: sub
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
/**
* string.sub (s, i [, j])
*
* Returns the substring of s that starts at i and continues until j;
* i and j may be negative. If j is absent, then it is assumed to be equal to -1
* (which is the same as the string length). In particular, the call
* string.sub(s,1,j)
* returns a prefix of s with length j, and
* string.sub(s, -i)
* returns a suffix of s with length i.
*/
static Varargs sub(Varargs args) {
final LuaString s = args.checkstring(1);
final int l = s.length();
int start = posrelat(args.checkint(2), l);
int end = posrelat(args.optint(3, -1), l);
if (start < 1)
start = 1;
if (end > l)
end = l;
if (start <= end) {
return s.substring(start - 1, end);
} else {
return EMPTYSTRING;
}
}
示例4: invoke
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
public Varargs invoke(Varargs args) {
LuaString name = args.checkstring(1);
InputStream is = null;
// get package path
LuaValue path = package_.get(_PATH);
if ( ! path.isstring() )
return valueOf("package.path is not a string");
// get the searchpath function.
Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));
// Did we get a result?
if (!v.isstring(1))
return v.arg(2).tostring();
LuaString filename = v.arg1().strvalue();
// Try to load the file.
v = globals.loadfile(filename.tojstring());
if ( v.arg1().isfunction() )
return LuaValue.varargsOf(v.arg1(), filename);
// report error
return varargsOf(NIL, valueOf("'"+filename+"': "+v.arg(2).tojstring()));
}
示例5: invoke
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
public Varargs invoke(Varargs args) {
LuaString s = args.checkstring(1);
int l = s.m_length;
int posi = posrelat( args.optint(2,1), l );
int pose = posrelat( args.optint(3,posi), l );
int n,i;
if (posi <= 0) posi = 1;
if (pose > l) pose = l;
if (posi > pose) return NONE; /* empty interval; return no values */
n = (int)(pose - posi + 1);
if (posi + n <= pose) /* overflow? */
error("string slice too long");
LuaValue[] v = new LuaValue[n];
for (i=0; i<n; i++)
v[i] = valueOf(s.luaByte(posi+i-1));
return varargsOf(v);
}
示例6: rep
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
/**
* string.rep (s, n)
*
* Returns a string that is the concatenation of n copies of the string s.
*/
static Varargs rep(Varargs args) {
LuaString s = args.checkstring(1);
int n = args.checkint(2);
final byte[] bytes = new byte[s.length() * n];
int len = s.length();
for (int offset = 0; offset < bytes.length; offset += len) {
s.copyInto(0, bytes, offset, len);
}
return LuaString.valueOf(bytes);
}
示例7: invoke
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
public Varargs invoke(Varargs args) {
LuaString src = args.checkstring( 1 );
final int srclen = src.length();
LuaString p = args.checkstring( 2 );
LuaValue repl = args.arg( 3 );
int max_s = args.optint( 4, srclen + 1 );
final boolean anchor = p.length() > 0 && p.charAt( 0 ) == '^';
Buffer lbuf = new Buffer( srclen );
MatchState ms = new MatchState( args, src, p );
int soffset = 0;
int n = 0;
while ( n < max_s ) {
ms.reset();
int res = ms.match( soffset, anchor ? 1 : 0 );
if ( res != -1 ) {
n++;
ms.add_value( lbuf, soffset, res, repl );
}
if ( res != -1 && res > soffset )
soffset = res;
else if ( soffset < srclen )
lbuf.append( (byte) src.luaByte( soffset++ ) );
else
break;
if ( anchor )
break;
}
lbuf.append( src.substring( soffset, srclen ) );
return varargsOf(lbuf.tostring(), valueOf(n));
}
示例8: str_find_aux
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
/**
* This utility method implements both string.find and string.match.
*/
static Varargs str_find_aux(Varargs args, boolean find) {
LuaString s = args.checkstring(1);
LuaString pat = args.checkstring(2);
int init = args.optint(3, 1);
if (init > 0) {
init = Math.min(init - 1, s.length());
} else if (init < 0) {
init = Math.max(0, s.length() + init);
}
boolean fastMatch = find && (args.arg(4).toboolean() || pat.indexOfAny(SPECIALS) == -1);
if (fastMatch) {
int result = s.indexOf(pat, init);
if (result != -1) {
return varargsOf(valueOf(result + 1), valueOf(result + pat.length()));
}
} else {
MatchState ms = new MatchState(args, s, pat);
boolean anchor = false;
int poff = 0;
if (pat.luaByte(0) == '^') {
anchor = true;
poff = 1;
}
int soff = init;
do {
int res;
ms.reset();
if ((res = ms.match(soff, poff)) != -1) {
if (find) {
return varargsOf(valueOf(soff + 1), valueOf(res), ms.push_captures(false, soff, res));
} else {
return ms.push_captures(true, soff, res);
}
}
} while (soff++ < s.length() && !anchor);
}
return NIL;
}
示例9: loadlib
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
public Varargs loadlib( Varargs args ) {
args.checkstring(1);
return varargsOf(NIL, valueOf("dynamic libraries not enabled"), valueOf("absent"));
}
示例10: str_find_aux
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
/**
* This utility method implements both string.find and string.match.
*/
static Varargs str_find_aux( Varargs args, boolean find ) {
LuaString s = args.checkstring( 1 );
LuaString pat = args.checkstring( 2 );
int init = args.optint( 3, 1 );
if ( init > 0 ) {
init = Math.min( init - 1, s.length() );
} else if ( init < 0 ) {
init = Math.max( 0, s.length() + init );
}
boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 );
if ( fastMatch ) {
int result = s.indexOf( pat, init );
if ( result != -1 ) {
return varargsOf( valueOf(result+1), valueOf(result+pat.length()) );
}
} else {
MatchState ms = new MatchState( args, s, pat );
boolean anchor = false;
int poff = 0;
if ( pat.luaByte( 0 ) == '^' ) {
anchor = true;
poff = 1;
}
int soff = init;
do {
int res;
ms.reset();
if ( ( res = ms.match( soff, poff ) ) != -1 ) {
if ( find ) {
return varargsOf( valueOf(soff+1), valueOf(res), ms.push_captures( false, soff, res ));
} else {
return ms.push_captures( true, soff, res );
}
}
} while ( soff++ < s.length() && !anchor );
}
return NIL;
}
示例11: gsub
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
/**
* string.gsub (s, pattern, repl [, n])
* Returns a copy of s in which all (or the first n, if given) occurrences of the
* pattern have been replaced by a replacement string specified by repl, which
* may be a string, a table, or a function. gsub also returns, as its second value,
* the total number of matches that occurred.
*
* If repl is a string, then its value is used for replacement.
* The character % works as an escape character: any sequence in repl of the form %n,
* with n between 1 and 9, stands for the value of the n-th captured substring (see below).
* The sequence %0 stands for the whole match. The sequence %% stands for a single %.
*
* If repl is a table, then the table is queried for every match, using the first capture
* as the key; if the pattern specifies no captures, then the whole match is used as the key.
*
* If repl is a function, then this function is called every time a match occurs,
* with all captured substrings passed as arguments, in order; if the pattern specifies
* no captures, then the whole match is passed as a sole argument.
*
* If the value returned by the table query or by the function call is a string or a number,
* then it is used as the replacement string; otherwise, if it is false or nil,
* then there is no replacement (that is, the original match is kept in the string).
*
* Here are some examples:
* x = string.gsub("hello world", "(%w+)", "%1 %1")
* --> x="hello hello world world"
*
* x = string.gsub("hello world", "%w+", "%0 %0", 1)
* --> x="hello hello world"
*
* x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")
* --> x="world hello Lua from"
*
* x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)
* --> x="home = /home/roberto, user = roberto"
*
* x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)
* return loadstring(s)()
* end)
* --> x="4+5 = 9"
*
* local t = {name="lua", version="5.1"}
* x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)
* --> x="lua-5.1.tar.gz"
*/
static Varargs gsub(Varargs args) {
LuaString src = args.checkstring(1);
final int srclen = src.length();
LuaString p = args.checkstring(2);
LuaValue repl = args.arg(3);
int max_s = args.optint(4, srclen + 1);
final boolean anchor = p.length() > 0 && p.charAt(0) == '^';
Buffer lbuf = new Buffer(srclen);
MatchState ms = new MatchState(args, src, p);
int soffset = 0;
int n = 0;
while (n < max_s) {
ms.reset();
int res = ms.match(soffset, anchor ? 1 : 0);
if (res != -1) {
n++;
ms.add_value(lbuf, soffset, res, repl);
}
if (res != -1 && res > soffset)
soffset = res;
else if (soffset < srclen)
lbuf.append((byte) src.luaByte(soffset++));
else
break;
if (anchor)
break;
}
lbuf.append(src.substring(soffset, srclen));
return varargsOf(lbuf.tostring(), valueOf(n));
}
示例12: gmatch
import org.luaj.vm2.Varargs; //导入方法依赖的package包/类
/**
* string.gmatch (s, pattern)
*
* Returns an iterator function that, each time it is called, returns the next captures
* from pattern over string s. If pattern specifies no captures, then the
* whole match is produced in each call.
*
* As an example, the following loop
* s = "hello world from Lua"
* for w in string.gmatch(s, "%a+") do
* print(w)
* end
*
* will iterate over all the words from string s, printing one per line.
* The next example collects all pairs key=value from the given string into a table:
* t = {}
* s = "from=world, to=Lua"
* for k, v in string.gmatch(s, "(%w+)=(%w+)") do
* t[k] = v
* end
*
* For this function, a '^' at the start of a pattern does not work as an anchor,
* as this would prevent the iteration.
*/
static Varargs gmatch(Varargs args) {
LuaString src = args.checkstring(1);
LuaString pat = args.checkstring(2);
return new GMatchAux(args, src, pat);
}