本文整理匯總了Java中org.luaj.vm2.LuaValue.invoke方法的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.invoke方法的具體用法?Java LuaValue.invoke怎麽用?Java LuaValue.invoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.luaj.vm2.LuaValue
的用法示例。
在下文中一共展示了LuaValue.invoke方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: callFunction
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public static Varargs callFunction(LuaValue target, Object... objs) {
if (target != null && target.isfunction()) {
LuaValue[] args = null;
if (objs != null && objs.length > 0) {
args = new LuaValue[objs.length];
for (int i = 0; i < objs.length; i++) {
args[i] = CoerceJavaToLua.coerce(objs[i]);
}
}
if (args != null) {
return target.invoke(LuaValue.varargsOf(args));
} else {
return target.call();
}
}
return LuaValue.NIL;
}
示例2: luaMain
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/** Simple wrapper for invoking a lua function with command line arguments.
* The supplied function is first given a new Globals object,
* then the program is run with arguments.
*/
public static void luaMain(LuaValue mainChunk, String[] args) {
Globals g = standardGlobals();
int n = args.length;
LuaValue[] vargs = new LuaValue[args.length];
for (int i = 0; i < n; ++i)
vargs[i] = LuaValue.valueOf(args[i]);
LuaValue arg = LuaValue.listOf(vargs);
arg.set("n", n);
g.set("arg", arg);
mainChunk.initupvalue1(g);
mainChunk.invoke(LuaValue.varargsOf(vargs));
}
示例3: invoke
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
@Override
public Varargs invoke(Varargs args) {
LuaValue key = args.arg(2);
Varargs newargs = varargsOf(args.arg(1), args.arg(3));
LuaValue func = metatable.get(key);
if (func.isfunction()) {//函數調用
func.invoke(newargs);
} else {
LogUtil.d("[LuaView error]", "property not fount :", key.toString());
}
return NONE;
}
示例4: invokeFunction
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* call lua function ( return multiple values)
*
* @param target
* @return
*/
public static Varargs invokeFunction(LuaValue target) {
try {
return (target != null && target.isfunction()) ? target.invoke() : LuaValue.NIL;
} catch (Exception e) {
e.printStackTrace();
return LuaValue.NIL;
}
}
示例5: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public LuaValue call( LuaValue arg ) {
LuaString name = arg.checkstring();
LuaValue loaded = package_.get(_LOADED);
LuaValue result = loaded.get(name);
if ( result.toboolean() ) {
if ( result == _SENTINEL )
error("loop or previous error loading module '"+name+"'");
return result;
}
/* else must load it; iterate over available loaders */
LuaTable tbl = package_.get(_SEARCHERS).checktable();
StringBuffer sb = new StringBuffer();
Varargs loader = null;
for ( int i=1; true; i++ ) {
LuaValue searcher = tbl.get(i);
if ( searcher.isnil() ) {
error( "module '"+name+"' not found: "+name+sb );
}
/* call loader with module name as argument */
loader = searcher.invoke(name);
if ( loader.isfunction(1) )
break;
if ( loader.isstring(1) )
sb.append( loader.tojstring(1) );
}
// load the module using the loader
loaded.set(name, _SENTINEL);
result = loader.arg1().call(name, loader.arg(2));
if ( ! result.isnil() )
loaded.set( name, result );
else if ( (result = loaded.get(name)) == _SENTINEL )
loaded.set( name, result = LuaValue.TRUE );
return result;
}
示例6: luaMain
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* Simple wrapper for invoking a lua function with command line arguments.
* The supplied function is first given a new Globals object,
* then the program is run with arguments.
*/
public static void luaMain(LuaValue mainChunk, String[] args) {
Globals g = standardGlobals();
int n = args.length;
LuaValue[] vargs = new LuaValue[args.length];
for (int i = 0; i < n; ++i)
vargs[i] = LuaValue.valueOf(args[i]);
LuaValue arg = LuaValue.listOf(vargs);
arg.set("n", n);
g.set("arg", arg);
mainChunk.initupvalue1(g);
mainChunk.invoke(LuaValue.varargsOf(vargs));
}
示例7: testLuaRunner
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
@Test
public void testLuaRunner() {
String luaScript = Utils.toString(new File("lua_test/test.lua"));
Globals globals = JsePlatform.standardGlobals();
LuaValue value = globals.load(luaScript);
value.invoke();
}
示例8: luaMain
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/** Simple wrapper for invoking a lua function with command line arguments.
* The supplied function is first given a new Globals object,
* then the program is run with arguments.
*/
public static void luaMain(LuaValue mainChunk, String[] args) {
Globals g = standardGlobals();
int n = args.length;
LuaValue[] vargs = new LuaValue[args.length];
for (int i = 0; i < n; ++i)
vargs[i] = LuaValue.valueOf(args[i]);
LuaValue arg = LuaValue.listOf(vargs);
arg.set("n", n);
g.set("arg", arg);
mainChunk.initupvalue1(g);
mainChunk.invoke(LuaValue.varargsOf(vargs));
}
示例9: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public LuaValue call(LuaValue arg) {
LuaString name = arg.checkstring();
LuaValue loaded = package_.get(_LOADED);
LuaValue result = loaded.get(name);
if (result.toboolean()) {
if (result == _SENTINEL)
error("loop or previous error loading module '" + name + "'");
return result;
}/* else if (globals != null && (result = globals.lazyLoad(name.checkjstring())) != null){//TODO add by song, 如果是加載自定義的內容則使用globals加載
loaded.set(name, _SENTINEL);
return result;
}*/
/* else must load it; iterate over available loaders */
LuaTable tbl = package_.get(_SEARCHERS).checktable();
StringBuffer sb = new StringBuffer();
Varargs loader = null;
for (int i = 1; true; i++) {
LuaValue searcher = tbl.get(i);
if (searcher.isnil()) {
error("module '" + name + "' not found: " + name + sb);
}
/* call loader with module name as argument */
loader = searcher.invoke(name);
if (loader.isfunction(1))
break;
if (loader.isstring(1))
sb.append(loader.tojstring(1));
}
// load the module using the loader
loaded.set(name, _SENTINEL);
try {
result = loader.arg1().call(name, loader.arg(2));
if (!result.isnil())
loaded.set(name, result);
else if ((result = loaded.get(name)) == _SENTINEL)
loaded.set(name, result = LuaValue.TRUE);
return result;
} catch (Exception e){
LogUtil.e("[PackageLib]", name, "load failed!", e);
return NIL;
}
}