本文整理匯總了Java中org.luaj.vm2.LuaValue.call方法的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.call方法的具體用法?Java LuaValue.call怎麽用?Java LuaValue.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.luaj.vm2.LuaValue
的用法示例。
在下文中一共展示了LuaValue.call方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeScript
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* 執行腳本
*
* @param value
* @param activity
* @param viewObj
* @param callback
*/
public boolean executeScript(LuaValue value, LuaValue activity, LuaValue viewObj, final LuaScriptLoader.ScriptExecuteCallback callback) {
try {
if (mGlobals != null && value != null) {
mGlobals.saveContainer(getRenderTarget());
mGlobals.set(LV_WINDOW, mWindowUserdata);//TODO 優化到其他地方?,設置window對象
value.call(activity, viewObj);
mGlobals.restoreContainer();
if (callback != null) {
callback.onScriptExecuted(getUri(), true);
}
return true;
}
} catch (Exception e) {
e.printStackTrace();
LogUtil.e("[Executed Script Failed]", e);
}
if (callback != null) {
callback.onScriptExecuted(getUri(), false);
}
return false;
}
示例2: 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;
}
示例3: main
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
//Globals globals = JsePlatform.standardGlobals();
Globals globals = new Globals();
globals.load(new JseBaseLib());
globals.load(new PackageLib());
globals.load(new Bit32Lib());
globals.load(new TableLib());
globals.load(new StringLib());
globals.load(new CoroutineLib());
globals.load(new JseMathLib());
globals.load(new JseIoLib());
globals.load(new JseOsLib());
globals.load(new JavaLibInteractionTest());
LoadState.install(globals);
LuaC.install(globals);
System.out.println(new File(".").getAbsolutePath());
System.out.println(new File(args[0]).exists());
LuaValue chunk = globals.loadfile(new File(args[0]).getAbsolutePath());
chunk.call();
}
示例4: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public LuaValue call(LuaValue arg) {
LuaValue h = arg.metatag(TOSTRING);
if (!h.isnil())
return h.call(arg);
LuaValue v = arg.tostring();
if (!v.isnil())
return v;
return valueOf(arg.tojstring());
}
示例5: 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;
}
}
示例6: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public LuaValue call(LuaValue arg) {
LuaValue h = arg.metatag(TOSTRING);
if (!h.isnil()) {
return h.call(arg);
}
LuaValue v = arg.tostring();
if (!v.isnil()) {
return v;
}
return valueOf(arg.tojstring());
}
示例7: runFunction
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
@Override
public void runFunction(String functionName) {
LuaValue v = mGlobals.get(functionName);
if (v != null) {
v.call();
}
}
示例8: execute
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
@Test
public void execute() throws Exception {
Globals globals = JsePlatform.standardGlobals();
// globals.set("LCallback", new LCallback());
LuaValue value = globals.load(helloWorldScript);
value.call();
}
示例9: restartCycle
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* Restarts the call cycle.
* Resets the current call number to one and calls init from the script.
*/
private void restartCycle() {
currentCallNum = 1;
cookieManager.getCookieStore().removeAll();
LuaValue cycleInit = luaGlobals.get(LUA_CYCLE_INIT);
if (!cycleInit.isnil()) {
cycleInit.call();
}
}
示例10: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public LuaValue call(LuaValue arg) {
LuaValue h = arg.metatag(TOSTRING);
if ( ! h.isnil() )
return h.call(arg);
LuaValue v = arg.tostring();
if ( ! v.isnil() )
return v;
return valueOf(arg.tojstring());
}
示例11: runLua
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* Parse and run Lua code.
* @param code Lua code.
* @param args Arguments passed to code.
*/
public static void runLua(String code, LuaValue[] args) {
LuaValue val;
// check if code is in script
if (code.charAt(0) == SCRIPT_MARK) {
String scriptPath = game.getFilePath(code.substring(1, code.indexOf(":")));
String fname = code.substring(code.indexOf(":") + 1);
// load script
lua.get("dofile").call(LuaValue.valueOf(scriptPath));
// load function in script
val = lua.get(fname);
} else {
val = lua.load(code);
}
// because call() method have not array argument
switch (args.length) {
case 0:
val.call();
break;
case 1:
val.call(args[0]);
break;
case 2:
val.call(args[0], args[1]);
break;
case 3:
val.call(args[0], args[1], args[2]);
break;
default:
throw new IllegalArgumentException(String.format("Illegal number of arguments! Min: 0, Max: 3, Your: %d", args.length));
}
}
示例12: run
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
@Override
public void run(String script) {
HNLog.d(HNLog.SANDBOX, "Execute script \"" + script + "\".");
LuaValue l = mGlobals.load(script);
l.call();
}