当前位置: 首页>>代码示例>>Java>>正文


Java LuaFunction.invoke方法代码示例

本文整理汇总了Java中org.luaj.vm2.LuaFunction.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java LuaFunction.invoke方法的具体用法?Java LuaFunction.invoke怎么用?Java LuaFunction.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.luaj.vm2.LuaFunction的用法示例。


在下文中一共展示了LuaFunction.invoke方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: method

import org.luaj.vm2.LuaFunction; //导入方法依赖的package包/类
@RuntimeType
public Object method(@Origin Method aMethod, @This Object o, @AllArguments Object[] objects,
		@SuperCall Callable supercall) {
	LuaValue value = delegations.get(aMethod.getName());
	if (value.isnil()) {
		try {
			return supercall.call();
		} catch (Exception e) {
			throw new DynamicDelegationError("Supercall threw exception - no delegation supplied", e);
		}
	}
	if (value.isfunction()) {
		LuaFunction function = value.checkfunction();
		LuaValue[] parameters = convertParamsToLua(o, objects, supercall);
		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);
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:23,代码来源:LuaGeneration.java

示例2: processScript

import org.luaj.vm2.LuaFunction; //导入方法依赖的package包/类
private static void processScript(InputStream script, String chunkname, String[] args, int firstarg)
{
	try
	{
		LuaFunction c;
		try
		{
			c = LuaC.load(script, chunkname, _G);
		}
		finally
		{
			script.close();
		}
		Varargs scriptargs = (args != null ? setGlobalArg(args, firstarg) : LuaValue.NONE);
		c.invoke(scriptargs);
	}
	catch(Exception e)
	{
		e.printStackTrace(System.err);
	}
}
 
开发者ID:dwing4g,项目名称:luaj,代码行数:22,代码来源:lua.java

示例3: constructor

import org.luaj.vm2.LuaFunction; //导入方法依赖的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);
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:13,代码来源:LuaGeneration.java

示例4: constructor

import org.luaj.vm2.LuaFunction; //导入方法依赖的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);
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:9,代码来源:LuaGeneration.java

示例5: executeMethod

import org.luaj.vm2.LuaFunction; //导入方法依赖的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));
    }
}
 
开发者ID:AlexMog,项目名称:SurvivalMMO,代码行数:10,代码来源:ScriptableComponent.java

示例6: execute

import org.luaj.vm2.LuaFunction; //导入方法依赖的package包/类
protected static void execute(LuaTable globals, boolean compileOnly) {
	if (QUIET) installQuite(globals);

	try {
		InputStream aesStream = PerformanceRunner.class.getResourceAsStream("/org/squiddev/luaj/luajc/aes/AesLua.lua");
		InputStream speedStream = PerformanceRunner.class.getResourceAsStream("/org/squiddev/luaj/luajc/aes/AesSpeed.lua");

		long start = System.nanoTime();
		LuaFunction aes = LoadState.load(aesStream, "AesLua.lua", globals);
		LuaFunction speed = LoadState.load(speedStream, "AesSpeed.lua", globals);

		long compiled = System.nanoTime();

		if (!compileOnly) {
			aes.invoke();
			for (int i = 0; i < 10; i++) {
				speed.invoke();
			}
		}

		long finished = System.nanoTime();

		System.out.printf("\n\tCompilation: %1$f\n\tRunning: %2$f\n", (compiled - start) / 1e9, (finished - compiled) / 1e9);
		System.out.flush();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:SquidDev,项目名称:luaj.luajc,代码行数:29,代码来源:PerformanceRunner.java

示例7: fireEvent

import org.luaj.vm2.LuaFunction; //导入方法依赖的package包/类
public static void fireEvent(String event, EventArgument<?> argument) {
    Set<LuaFunction> set = eventHandlers.get(event);
    if (set != null) {
        for (LuaFunction function : set) {
            function.invoke(argument);
        }
    }
}
 
开发者ID:dmillerw,项目名称:MineLua,代码行数:9,代码来源:EventHandler.java

示例8: call

import org.luaj.vm2.LuaFunction; //导入方法依赖的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");
}
 
开发者ID:LoDoMa,项目名称:Lime,代码行数:14,代码来源:LuaScript.java

示例9: asLuaTask

import org.luaj.vm2.LuaFunction; //导入方法依赖的package包/类
/**
 * Generates a {@link Task} based on the contents of the
 * provided Lua value.
 * 
 * <p>The value may be one of two types, either a table
 * (full implementation) or a function (process function
 * only).</p>
 * 
 * <p>If the value is a function, the task returned
 * contains nothing but the Lua script assigned to run
 * when this task is executed.</p>
 * 
 * <p>If the value is a table, then the task returned is
 * a full implementation based on the properties of the
 * table. The following keys are read from the
 * table.</p>
 * 
 * <pre>
 * "name": {@link #getName()},
 * "process": {@link #process()},
 * "onFinish": {@link #onFinish(boolean)}
 * </pre>
 * 
 * <p>The two functions of the tasks gain parameters
 * based on whether or not the provided value was a
 * function or a table. If a function, the functions
 * gain no extra values, otherwise the first argument
 * for both functions is always the table implementing
 * the task.</p>
 * 
 * @param value the value containing the task properties
 * 
 * @return a Lua-made Task
 */
public static Task asLuaTask(LuaValue value) {
    if(value.isfunction()) {
        return () -> {
            return value.invoke().toboolean(1);
        };
    } else if(value.istable()) {
        LuaTable table = value.checktable();
        return new Task() {
            @Override
            public String getName() {
                return table.get(FIELD_NAME).optjstring(null);
            }

            @Override
            public boolean process() {
                return table.get(FUNC_PROCESS).checkfunction().invoke(table).toboolean(1);
            }

            @Override
            public void onFinish(boolean forced) {
                LuaFunction func = table.get(FUNC_ONFINISH).optfunction(null);
                if(func != null) {
                    func.invoke(table, LuaValue.valueOf(forced));
                }
            }
        };
    } else {
        throw new LuaError("bad argument: expected function or table, got " + value.typename());
    }
}
 
开发者ID:Xemiru,项目名称:Undertailor,代码行数:65,代码来源:Task.java


注:本文中的org.luaj.vm2.LuaFunction.invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。