本文整理匯總了Java中org.luaj.vm2.LuaValue.isfunction方法的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.isfunction方法的具體用法?Java LuaValue.isfunction怎麽用?Java LuaValue.isfunction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.luaj.vm2.LuaValue
的用法示例。
在下文中一共展示了LuaValue.isfunction方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: method
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
@RuntimeType
public Object method(@Origin Method aMethod, @This Object o, @AllArguments Object[] objects) {
LuaValue value = delegations.get(aMethod.getName());
if (value.isnil())
return null;
if (value.isfunction()) {
LuaFunction function = value.checkfunction();
LuaValue[] parameters = convertParamsToLua(o, objects);
Varargs invoke = function.invoke(parameters);
if (aMethod.getReturnType() == Void.class || invoke.narg() == 0)
return null;
return LuaConversion.convertToJava(aMethod.getReturnType(), invoke.checkvalue(1));
} else {
return LuaConversion.convertToJava(aMethod.getReturnType(), value);
}
}
示例2: onCellClicked
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* 調用 Callback 方法
*
* @param cell
* @param position
* @return
*/
public LuaValue onCellClicked(LuaValue cell, int position) {
final int section = getSectionByPosition(position);
final int row = getRowInSectionByPosition(position);
final String id = getId(position, section, row);
final LuaValue cellData = getCell(id);
if (cellData != null) {
final LuaValue callback = cellData.get("Callback");
if (callback.isfunction()) {
return LuaUtil.callFunction(callback, cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
} else if (callback.istable()) {
return LuaUtil.callFunction(LuaUtil.getFunction(callback, "Click", "click"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
}
}
return NIL;
}
示例3: 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;
}
示例4: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
@Override
public final LuaValue call(LuaValue arg1, LuaValue arg2) {
if (!arg1.isnumber() || !arg2.isfunction()) {
return LuaValue.FALSE;
}
// Queue up action for later
new Thread(() -> {
ClientAPIUtils.sleep(arg1.toint());
arg2.invoke();
}).start();
return LuaValue.TRUE;
}
示例5: constructor
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public void constructor(@This Object o, @AllArguments Object[] objects) { // @Origin
// Constructor
// constructor,
LuaValue value = delegations.get("__new__");
if (value.isnil())
return;
if (!value.isfunction())
throw new DynamicDelegationError("__new__ for " + o.getClass().getName() + " is a " + value.typename());
LuaFunction function = value.checkfunction();
LuaValue[] parameters = convertParamsToLua(o, objects);
function.invoke(parameters);
}
示例6: 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;
}
}
示例7: getOrCallFunction
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* 調用方法或者直接取數據
*
* @param target
* @return
*/
public static LuaValue getOrCallFunction(LuaValue target) {
try {
return (target != null && target.isfunction()) ? target.call() : target;
} catch (Exception e) {
e.printStackTrace();
return LuaValue.NIL;
}
}
示例8: constructor
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public void constructor(@This Object o, @AllArguments Object[] objects) { // @Origin Constructor constructor,
LuaValue value = delegations.get("__new__");
if (value.isnil()) return;
if (!value.isfunction()) throw new DynamicDelegationError("__new__ for " + o.getClass().getName() + " is a " + value.typename());
LuaFunction function = value.checkfunction();
LuaValue[] parameters = convertParamsToLua(o, objects);
function.invoke(parameters);
}
示例9: invoke
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public Varargs invoke(Varargs args) {
int a = 1;
LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running;
LuaValue func = args.arg(a++);
String what = args.optjstring(a++, "flnStu");
DebugLib.CallStack callstack = callstack(thread);
// find the stack info
DebugLib.CallFrame frame;
if (func.isnumber()) {
frame = callstack.getCallFrame(func.toint());
if (frame == null)
return NONE;
func = frame.f;
} else if (func.isfunction()) {
frame = callstack.findCallFrame(func);
} else {
return argerror(a - 2, "function or level");
}
// start a table
DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame);
LuaTable info = new LuaTable();
if (what.indexOf('S') >= 0) {
info.set(WHAT, LUA);
info.set(SOURCE, valueOf(ar.source));
info.set(SHORT_SRC, valueOf(ar.short_src));
info.set(LINEDEFINED, valueOf(ar.linedefined));
info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined));
}
if (what.indexOf('l') >= 0) {
info.set(CURRENTLINE, valueOf(ar.currentline));
}
if (what.indexOf('u') >= 0) {
info.set(NUPS, valueOf(ar.nups));
info.set(NPARAMS, valueOf(ar.nparams));
info.set(ISVARARG, ar.isvararg ? ONE : ZERO);
}
if (what.indexOf('n') >= 0) {
info.set(NAME, LuaValue.valueOf(ar.name != null ? ar.name : "?"));
info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat));
}
if (what.indexOf('t') >= 0) {
info.set(ISTAILCALL, ZERO);
}
if (what.indexOf('L') >= 0) {
LuaTable lines = new LuaTable();
info.set(ACTIVELINES, lines);
DebugLib.CallFrame cf;
for (int l = 1; (cf = callstack.getCallFrame(l)) != null; ++l)
if (cf.f == func)
lines.insert(-1, valueOf(cf.currentline()));
}
if (what.indexOf('f') >= 0) {
if (func != null)
info.set(FUNC, func);
}
return info;
}
示例10: invoke
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public Varargs invoke(Varargs args) {
int a=1;
LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
LuaValue func = args.arg(a++);
String what = args.optjstring(a++, "flnStu");
DebugLib.CallStack callstack = callstack(thread);
// find the stack info
DebugLib.CallFrame frame;
if ( func.isnumber() ) {
frame = callstack.getCallFrame(func.toint());
if (frame == null)
return NONE;
func = frame.f;
} else if ( func.isfunction() ) {
frame = callstack.findCallFrame(func);
} else {
return argerror(a-2, "function or level");
}
// start a table
DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame);
LuaTable info = new LuaTable();
if (what.indexOf('S') >= 0) {
info.set(WHAT, LUA);
info.set(SOURCE, valueOf(ar.source));
info.set(SHORT_SRC, valueOf(ar.short_src));
info.set(LINEDEFINED, valueOf(ar.linedefined));
info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined));
}
if (what.indexOf('l') >= 0) {
info.set( CURRENTLINE, valueOf(ar.currentline) );
}
if (what.indexOf('u') >= 0) {
info.set(NUPS, valueOf(ar.nups));
info.set(NPARAMS, valueOf(ar.nparams));
info.set(ISVARARG, ar.isvararg? ONE: ZERO);
}
if (what.indexOf('n') >= 0) {
info.set(NAME, LuaValue.valueOf(ar.name!=null? ar.name: "?"));
info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat));
}
if (what.indexOf('t') >= 0) {
info.set(ISTAILCALL, ZERO);
}
if (what.indexOf('L') >= 0) {
LuaTable lines = new LuaTable();
info.set(ACTIVELINES, lines);
DebugLib.CallFrame cf;
for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l)
if (cf.f == func)
lines.insert(-1, valueOf(cf.currentline()));
}
if (what.indexOf('f') >= 0) {
if (func != null)
info.set( FUNC, func );
}
return info;
}