本文整理汇总了Java中org.luaj.vm2.lib.jse.CoerceJavaToLua.coerce方法的典型用法代码示例。如果您正苦于以下问题:Java CoerceJavaToLua.coerce方法的具体用法?Java CoerceJavaToLua.coerce怎么用?Java CoerceJavaToLua.coerce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.luaj.vm2.lib.jse.CoerceJavaToLua
的用法示例。
在下文中一共展示了CoerceJavaToLua.coerce方法的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: 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);
}
示例4: 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;
}
示例5: 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;
}
}
示例6: 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));
}
}
示例7: 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;
}
}
示例8: rawget
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
@Override
public LuaValue rawget(LuaValue key) {
if (key.isstring()) {
switch (key.checkjstring()) {
case "health":
if (entity.getEntity() instanceof Damageable) {
return LuaValue.valueOf(((Damageable) entity.getEntity()).getHealth());
}
break;
case "maxHealth":
if (entity.getEntity() instanceof Damageable) {
return LuaValue.valueOf(((Damageable) entity.getEntity()).getMaxHealth());
}
break;
case "name":
return LuaValue.valueOf(entity.getName());
case "secondName":
return LuaValue.valueOf(entity.getSecondName());
case "invulnerable":
return LuaValue.valueOf(!entity.isTakingDamage());
case "nameVisible":
return LuaValue.valueOf(entity.isNameVisible());
case "location":
return ScriptUtil.getLocation(entity.getNpc().getStoredLocation());
case "worldName":
return LuaValue.valueOf(entity.getEntity().getWorld().getName());
case "target":
return ScriptUtil.getTarget(entity);
case "bukkitEntity":
return CoerceJavaToLua.coerce(entity.getEntity());
case "npc":
return CoerceJavaToLua.coerce(entity.getNpc());
}
}
return super.rawget(key);
}
示例9: enter
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
@Override
public Object enter( String entryPointName, Executable executable, ExecutionContext executionContext, Object... arguments ) throws NoSuchMethodException, ParsingException, ExecutionException
{
entryPointName = toLuaStyle( entryPointName );
Globals globals = getGlobals( executionContext );
LuaValue entryPoint = globals.get( entryPointName );
if( entryPoint == LuaValue.NIL )
throw new NoSuchMethodException( entryPointName );
LuaValue[] luaArguments = new LuaValue[arguments.length];
for( int i = arguments.length - 1; i >= 0; i-- )
luaArguments[i] = CoerceJavaToLua.coerce( arguments[i] );
try
{
LuaValue r = entryPoint.invoke( luaArguments ).arg1();
if( r == LuaValue.NIL )
r = null;
return r;
}
catch( LuaError x )
{
throw createExecutionException( executable.getDocumentName(), x );
}
finally
{
globals.STDOUT.flush();
globals.STDERR.flush();
}
}
示例10: call
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
public LuaValue call( LuaValue table, LuaValue key )
{
if( key.isstring() )
return CoerceJavaToLua.coerce( executionContext.getServices().get( key.tojstring() ) );
else
return this.rawget( key );
}
示例11: executeFunction
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
/**
* Invokes a Lua function that is defined in the assigned entity.
*
* @param function
* name of the function
* @return a LuaValue representing the result of the call or
* <code>null</code> if the function does not exist
* @throws RuneScriptException
*/
public LuaValue executeFunction(String function, Object... args) throws RuneScriptException {
LuaValue func = luaGlobals.get(function);
if (func == null || func == LuaValue.NIL) {
// function not found
if (entity.getEngine().isOptionEnabled(RuneEngine.OPTION_STRICT_FUNCALL)) {
// throw exception when strict function calls are enabled
throw new RuneInvalidFunctionException(function);
}
return null;
}
if (!(func instanceof LuaFunction)) {
throw new RuneScriptException(function + " is not a function");
}
if (args.length < 1) {
return func.call();
} else {
// translate arguments into function parameters
LuaValue[] luaArgs = new LuaValue[args.length];
for (int i = 0; i < args.length; ++i) {
luaArgs[i] = CoerceJavaToLua.coerce(args[i]);
}
// execute with parameters
Varargs v = func.invoke(LuaValue.varargsOf(luaArgs));
// return according value
if (v.narg() <= 0) {
return LuaValue.NIL;
} else if (v.narg() == 1) {
return v.arg1();
} else {
return new LuaTable(v);
}
}
}
示例12: onEvent
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
@Override
public void onEvent(Object... data)
{
LuaValue[] luaArguments = new LuaValue[data.length];
for (int i = 0; i < data.length; i++)
luaArguments[i] = CoerceJavaToLua.coerce(data[i]);
Varargs returnedVarargs = function.invoke(luaArguments);
if (returnedVarargs.narg() != 0)
throw new LuaError("event function may not return anything");
}
示例13: call
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
public void call(LuaFunction function, Object[] arguments)
{
if(arguments == null)
arguments = new Object[0];
LuaValue[] luaArguments = new LuaValue[arguments.length];
for (int i = 0; i < arguments.length; i++)
luaArguments[i] = CoerceJavaToLua.coerce(arguments[i]);
Varargs returnedVarargs = function.invoke(luaArguments);
if (returnedVarargs.narg() != 0)
throw new LuaError("script functions may not return anything");
}
示例14: endContact
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
@Override
public void endContact(Contact contact) {
if(luaOnEndContactFunc == null)
return;
LuaValue luaContact = CoerceJavaToLua.coerce(contact);
luaOnEndContactFunc.call(luaContact);
}
示例15: beginContact
import org.luaj.vm2.lib.jse.CoerceJavaToLua; //导入方法依赖的package包/类
@Override
public void beginContact(Contact contact) {
if(luaOnBeginContactFunc == null)
return;
LuaValue luaContact = CoerceJavaToLua.coerce(contact);
luaOnBeginContactFunc.call(luaContact);
}