本文整理汇总了Java中org.luaj.vm2.lib.jse.CoerceJavaToLua类的典型用法代码示例。如果您正苦于以下问题:Java CoerceJavaToLua类的具体用法?Java CoerceJavaToLua怎么用?Java CoerceJavaToLua使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CoerceJavaToLua类属于org.luaj.vm2.lib.jse包,在下文中一共展示了CoerceJavaToLua类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: post
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
@Override
public final void post(Object event) {
// If the hook manager doesn't contain any hooks, ignore
if (hookManager.getHooks().isEmpty())
return;
// Coerce the event to a LuaValue
LuaValue luaEvent = CoerceJavaToLua.coerce(event);
// Call lua hook functions
hookManager.getHooks().values().forEach(hooks -> hooks.forEach(hook -> {
if (hook.isTargetEvent(event)) {
hook.invoke(luaEvent);
}
}));
}
示例2: callFunction
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的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: run
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
@Override
public void run(String name, Object... parameter) {
LuaFunction function = lua.getFunction(name);
if (parameter.length == 0) {
function.call();
} else {
if (parameter.length == 1) {
function.call(CoerceJavaToLua.coerce(parameter[0]));
}
if (parameter.length == 2) {
function.call(CoerceJavaToLua.coerce(parameter[0]), CoerceJavaToLua.coerce(parameter[1]));
}
if (parameter.length == 3) {
function.call(CoerceJavaToLua.coerce(parameter[0]), CoerceJavaToLua.coerce(parameter[1]),
CoerceJavaToLua.coerce(parameter[2]));
}
if (parameter.length > 3) {
throw new RuntimeException("Too many parameters in Lua function call: " + name);
}
}
}
示例4: call
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
@Override
public LuaValue call(LuaValue randomDefinition) {
RandomType randomType = LuaUtil.asEnum(randomDefinition, "type", RandomType.XORSHIFT_1024_STAR, RandomType.class);
RandomValueTransformer transformer = null;
if (randomDefinition.istable()) {
LuaValue transformFunction = randomDefinition.get("transform");
if (transformFunction.isfunction()) {
transformer = new LuaRandomValueTransformer(transformFunction);
}
} else if (randomDefinition.isfunction()) {
transformer = new LuaRandomValueTransformer(randomDefinition);
}
Random random = new Random(randomType, LuaUtil.asSeed(randomDefinition), transformer);
return CoerceJavaToLua.coerce(random);
}
示例5: callFunction
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
@Override
public Object callFunction (String name, Object[] args) {
LuaValue function = scriptTable.get(name);
if (function == LuaValue.NIL)
return LuaValue.NIL;
LuaValue returnValue = null;
switch (args.length) {
case 0:
returnValue = function.call();
break;
case 1:
returnValue = function.call(CoerceJavaToLua.coerce(args[0]));
break;
case 2:
returnValue = function.call(CoerceJavaToLua.coerce(args[0]), CoerceJavaToLua.coerce(args[1]));
break;
case 3:
returnValue = function.call(CoerceJavaToLua.coerce(args[0]), CoerceJavaToLua.coerce(args[1]),
CoerceJavaToLua.coerce(args[2]));
break;
}
return returnValue;
}
示例6: onPlayerMove
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
for (Region r : this.regions.values()) {
if (r.isInRegion(event.getTo())) {
if (!r.isInRegion(event.getFrom())) {
if (r.getEnterHandler() != null) {
RpgPlus.getPlugin(RpgPlus.class).getScriptingManager().invokeSafely(r.getEnterHandler(), LuaValue.varargsOf(new LuaValue[]{CoerceJavaToLua.coerce(event), CoerceJavaToLua.coerce(r)}));
}
}
} else if (r.isInRegion(event.getFrom())) {
if (r.getLeaveHandler() != null) {
RpgPlus.getPlugin(RpgPlus.class).getScriptingManager().invokeSafely(r.getLeaveHandler(), LuaValue.varargsOf(new LuaValue[]{CoerceJavaToLua.coerce(event), CoerceJavaToLua.coerce(r)}));
}
}
}
}
示例7: runMobScript
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
protected boolean runMobScript(String method, Object arg1, Object arg2) {
if (!mobScriptLoaded) {
mobScript=LuaEngine.module(scriptFile, DEFAULT_MOB_SCRIPT);
mobScriptLoaded = true;
}
if(mobScript != null) {
scriptResult = mobScript.invokemethod(method, new LuaValue[]{
CoerceJavaToLua.coerce(this),
CoerceJavaToLua.coerce(arg1),
CoerceJavaToLua.coerce(arg2)})
.arg1();
if(scriptResult.isboolean()) {
return scriptResult.checkboolean();
}
return true;
}
return false;
}
示例8: loadPrototype
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
/**
* load prototype (lua bytecode or sourcecode)
*
* @param inputStream
* @return
*/
public LuaViewCore loadPrototype(final InputStream inputStream, final String name, final LuaScriptLoader.ScriptExecuteCallback callback) {
new SimpleTask1<LuaValue>() {
@Override
protected LuaValue doInBackground(Object... params) {
try {
if (mGlobals != null) {
Prototype prototype = mGlobals.loadPrototype(inputStream, name, "bt");
if (prototype != null) {
LuaValue result = mGlobals.load(prototype, name);
return result;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(LuaValue value) {
final LuaValue activity = CoerceJavaToLua.coerce(mContext);
final LuaValue viewObj = CoerceJavaToLua.coerce(LuaViewCore.this);
if (callback == null || callback.onScriptCompiled(value, activity, viewObj) == false) {
executeScript(value, activity, viewObj, callback);
}
}
}.executeInPool();
return this;
}
示例9: register
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
/**
* 注册一个名称到该lua对象的命名空间中
*
* @param luaName
* @param obj
* @return
*/
public synchronized LuaViewCore register(final String luaName, final Object obj) {
if (mGlobals != null && !TextUtils.isEmpty(luaName)) {
final LuaValue value = mGlobals.get(luaName);
if (obj != value) {
mGlobals.set(luaName, CoerceJavaToLua.coerce(obj));
}
} else {
LogUtil.e("name " + luaName + " is invalid!");
}
return this;
}
示例10: getNativeView
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
/**
* get native view
*
* @return
*/
public LuaValue getNativeView() {
View view = getView();
if (view instanceof ILVNativeViewProvider) {
view = ((ILVNativeViewProvider) view).getNativeView();
}
return view != null ? CoerceJavaToLua.coerce(view) : LuaValue.NIL;
}
示例11: toLuaValue
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
/**
* convert object to LuaValue
*
* @param value
* @return
*/
public static LuaValue toLuaValue(Object value) {
try {
if (value instanceof Integer) {
return LuaValue.valueOf((Integer) value);
} else if (value instanceof Long) {
return LuaValue.valueOf((Long) value);
} else if (value instanceof Double) {
return LuaValue.valueOf((Double) value);
} else if (value instanceof String) {
return LuaValue.valueOf((String) value);
} else if (value instanceof Boolean) {
return LuaValue.valueOf((Boolean) value);
} else if (value instanceof byte[]) {
return LuaValue.valueOf((byte[]) value);
} else if (value instanceof List) {
return toTable((List) value);
} else if (value instanceof Map) {
return toTable((Map) value);
} else {
return CoerceJavaToLua.coerce(value);
}
} catch (Exception e) {
e.printStackTrace();
return LuaValue.NIL;
}
}
示例12: getGlobals
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
@NonNull
private Globals getGlobals() {
if (mLuaGlobals == null) {
final File hubDir =
HubsApplication.getDefaultFileManager(mContext).getHubDirectory(mHub.getId());
mLuaGlobals = new HubsLuaGlobals(hubDir);
mHub.setAllTo(mLuaGlobals);
final OkHttpClient client = HubsApplication.getDefaultOkHttpClient(mContext);
mLuaGlobals.loadfile(mHub.getEntry()).call(CoerceJavaToLua.coerce(client));
}
return mLuaGlobals;
}
示例13: executeMethod
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
public void executeMethod(Events e, Object...args) {
List<LuaFunction> list = mEventFunctions.get(e.ordinal());
if (list == null || list.size() == 0) return;
for (LuaFunction method : list) {
LuaValue[] vars = new LuaValue[args.length];
for (int i = 0; i < args.length; ++i) vars[i] = CoerceJavaToLua.coerce(args[i]);
if (method != null) method.invoke(LuaValue.varargsOf(vars));
}
}
示例14: Invoke_function
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
public Object Invoke_function(String func, Object... args) {
try {
LuaValue arg = CoerceJavaToLua.coerce(args[0]);
LuaFunction lfunc = (LuaFunction)bindings.get(func);
LuaValue rv = lfunc.call(arg);
return CoerceLuaToJava.coerce(rv, Object.class);
}
catch (Exception e) {
Gfo_script_engine__luaj.Warn("", "", "failed to invoke method; method=~{0} err=~{1}", func, Err_.Message_lang(e));
return null;
}
}
示例15: execute
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入依赖的package包/类
@Override
public boolean execute(CommandSender sender, String commandLabel,String[] args) {
// if(exe != null){
// exe.onCommand(sender, this, commandLabel,args);
// }
LuaValue[] args0 = new LuaValue[args.length];
for (int i = 0; i < args.length; i++) {
args0[i] = LuaValue.valueOf(args[i]);
}
boolean r = pluginNamespace.get("onCommand").call(CoerceJavaToLua.coerce(new LuaCommandSender(sender)), LuaValue.valueOf(commandLabel), LuaValue.listOf(args0)).checkboolean();
return r;
}