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


Java LuaError类代码示例

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


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

示例1: bindMethods

import org.luaj.vm2.LuaError; //导入依赖的package包/类
/**
 * bind lua functions using method
 *
 * @param factory
 * @param methods
 * @return
 */
public static LuaTable bindMethods(Class<? extends LibFunction> factory, List<Method> methods) {
    LuaTable env = new LuaTable();
    try {
        if (methods != null) {
            for (int i = 0; i < methods.size(); i++) {
                LibFunction f = factory.newInstance();
                f.opcode = -1;
                f.method = methods.get(i);
                f.name = methods.get(i).getName();
                env.set(f.name, f);
            }
        }
    } catch (Exception e) {
        throw new LuaError("[Bind Failed] " + e);
    } finally {
        return env;
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:26,代码来源:LuaViewManager.java

示例2: bind

import org.luaj.vm2.LuaError; //导入依赖的package包/类
/**
 * bind lua functions using opcode
 *
 * @param factory
 * @param methods
 * @return
 */
public static LuaTable bind(Class<? extends LibFunction> factory, List<String> methods) {
    LuaTable env = new LuaTable();
    try {
        if (methods != null) {
            for (int i = 0; i < methods.size(); i++) {
                LibFunction f = factory.newInstance();
                f.opcode = i;
                f.method = null;
                f.name = methods.get(i);
                env.set(f.name, f);
            }
        }
    } catch (Exception e) {
        throw new LuaError("[Bind Failed] " + e);
    } finally {
        return env;
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:26,代码来源:LuaViewManager.java

示例3: get

import org.luaj.vm2.LuaError; //导入依赖的package包/类
public LuaValue get(LuaValue key) {
	if ( jclass == null )
		jclass = JavaClass.forClass(m_instance.getClass());
	Field f = jclass.getField(key);
	if ( f != null )
		try {
			return CoerceJavaToLua.coerce(f.get(m_instance));
		} catch (Exception e) {
			throw new LuaError(e);
		}
	LuaValue m = jclass.getMethod(key);
	if ( m != null )
		return m;
	Class c = jclass.getInnerClass(key);
	if ( c != null )
		return JavaClass.forClass(c);
	return super.get(key);
}
 
开发者ID:hsllany,项目名称:HtmlNative,代码行数:19,代码来源:JavaInstance.java

示例4: invokeFor

import org.luaj.vm2.LuaError; //导入依赖的package包/类
private void invokeFor(Class[] parameters, Object[] param, Varargs args, Method method) {
	try {
		for (int i = 0; i < parameters.length; i++) {

			param[i] = LuaConversion.convertToJava(parameters[i], args.arg(i + 1));
		}
	} catch (Exception ignored) {
		continue;
	}
	try {
		Object invoke = method.invoke(null, param);
		return LuaConversion.convertToLua(invoke);
	} catch (Exception e) {
		throw new LuaError(e);
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:17,代码来源:LuaMethod.java

示例5: completed

import org.luaj.vm2.LuaError; //导入依赖的package包/类
public void completed(String message, SocketReader socketReader) throws IOException {
    final int valueSize = Integer.parseInt(message);
    final String valueString = socketReader.readBytes(valueSize);

    log.debug("Read value: " + valueString);
    try {
        Globals globals = JsePlatform.debugGlobals();
        LuaValue chunk = globals.load(valueString);
        LuaTable stackDump = chunk.call().checktable();  // Executes the chunk and returns it
        LuaRemoteStack.clearIdKey(stackDump);
        LuaValue rawValue = stackDump;
        if (stackDump.keyCount() == 1)
            rawValue = stackDump.get(1);
        else if (stackDump.keyCount() == 0)
            rawValue = LuaValue.NIL;
        LuaDebugValue value = new LuaDebugValue(rawValue, AllIcons.Debugger.Watch);
        myPromise.setResult(value);
    } catch (LuaError e) {
        LuaDebugValue errorValue = new LuaDebugValue(
                "error",
                "Error during evaluation: " + e.getMessage(),
                AllIcons.Nodes.ErrorMark
        );
        myPromise.setResult(errorValue);
    }
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:27,代码来源:LuaDebuggerController.java

示例6: getRunnableExecution

import org.luaj.vm2.LuaError; //导入依赖的package包/类
public Runnable getRunnableExecution(final String text) {
    return new FutureTask<Object>(new Runnable() {
        @Override
        public void run() {
            try {
                setStatus("[running...]");
                final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

                // evaluate Lua code from String
                final PrintStream stdout = _G.STDOUT;
                _G.STDOUT = new PrintStream(outputStream);
                _G.get("load").call(LuaValue.valueOf(text)).call();

                print(new String(outputStream.toByteArray(), CharsetToolkit.UTF8_CHARSET));
                _G.STDOUT = stdout;
            } catch (LuaError e) {
                printError(e);
            } finally {
                setStatus("");
            }
        }
    }, null);
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:24,代码来源:LuaJInterpreter.java

示例7: call

import org.luaj.vm2.LuaError; //导入依赖的package包/类
@Override
public LuaValue call(LuaValue arg) {
	if (limit == null) {
		throw new LuaError("Calling this function is not allowed in the current state.");
	}
	
	if (arg.isstring()) {
		String toLoad = arg.tojstring();
		
		toLoad = toLoad.replaceAll("\\.+", ".");
		toLoad = Paths.get(limit.toString(), toLoad).toString();
		
		return originalFunction.call(LuaValue.valueOf(toLoad));
	}
	
	return LuaValue.NIL;
}
 
开发者ID:quadracoatl,项目名称:quadracoatl,代码行数:18,代码来源:LuaEnvironment.java

示例8: checkType

import org.luaj.vm2.LuaError; //导入依赖的package包/类
/**
 * Returns the given {@link LuaValue} as the appropriate
 * type of {@link LuaObjectValue}, directed by the
 * provided {@link LuaObjectMeta} type.
 * 
 * <p>If the provided value is not of the appropriate
 * type, a {@link LuaError} is raised.</p>
 * 
 * @param value the LuaValue to check
 * @param clazz the target LuaObjectMeta type to check
 *        with
 * 
 * @return the appropriately typed LuaValue as a
 *         LuaObjectValue
 */
public static <T> LuaObjectValue<T> checkType(LuaValue value,
    Class<? extends LuaObjectMeta> clazz) {
    LuaObjectMeta meta = Lua.getMeta(clazz);
    if (meta == null) {
        throw new IllegalArgumentException(
            "Meta class " + clazz.getSimpleName() + " isn't registered");
    }

    if (value instanceof LuaObjectValue) {
        LuaObjectValue<?> objectValue = ((LuaObjectValue<?>) value);
        if (meta.getTargetObjectClass().isInstance(objectValue.getObject())) {
            return (LuaObjectValue<T>) objectValue;
        }
    }

    throw new LuaError(String.format(INVALID_TYPE_MSG, meta.getTypeName(), value.typename()));
}
 
开发者ID:Xemiru,项目名称:Undertailor,代码行数:33,代码来源:Lua.java

示例9: ColorsLib

import org.luaj.vm2.LuaError; //导入依赖的package包/类
public ColorsLib() {
    super("colors");

    set("fromHex", asFunction(vargs -> {
        String hex = vargs.checkjstring(1);
        if(hex.length() < 6) {
            throw new LuaError("bad argument: bad hex color string (must be at least 6 hexadecimal characters)");
        }

        return of(Color.valueOf(hex));
    }));

    set("fromRGB", asFunction(vargs -> {
        int r = vargs.optint(1, 0);
        int g = vargs.optint(2, 0);
        int b = vargs.optint(3, 0);
        return of(new Color(r / 255F, g / 255F, b / 255F, 1F));
    }));
}
 
开发者ID:Xemiru,项目名称:Undertailor,代码行数:20,代码来源:ColorsLib.java

示例10: LuaWorldRoom

import org.luaj.vm2.LuaError; //导入依赖的package包/类
public LuaWorldRoom(ScriptManager manager, File luaFile, Varargs params)
    throws FileNotFoundException, LuaScriptException {
    this();

    this.luaObj.load(manager, luaFile);

    String loadedMap = this.luaObj.get(FIELD_TILEMAP).optjstring(null);
    if (loadedMap != null) {
        Tilemap map = Undertailor.getInstance().getAssetManager().getTilemapManager()
            .getTilemap(loadedMap);
        if (map == null) {
            throw new LuaError("unknown tilemap " + loadedMap);
        }

        super.tilemap = map;
    }
}
 
开发者ID:Xemiru,项目名称:Undertailor,代码行数:18,代码来源:LuaWorldRoom.java

示例11: off

import org.luaj.vm2.LuaError; //导入依赖的package包/类
public LuaValue off(LuaValue inventoryWrapper, LuaValue eventName, LuaValue callback) {
    if (inventoryWrapper instanceof InventoryWrapper) {
        Inventory inventory = ((InventoryWrapper) inventoryWrapper).getInventory();
        if (eventName.isnil()) {
            return LuaValue.valueOf(!eventHandlers.remove(inventory).isEmpty());
        } else {
            Multimap<String, LuaFunction> handlers = eventHandlers.get(inventory);
            if (handlers != null) {
                if (callback.isnil()) {
                    return LuaValue.valueOf(!handlers.removeAll(eventName.checkjstring()).isEmpty());
                } else {
                    return LuaFunction.valueOf(handlers.remove(eventName.checkjstring(), callback.checkfunction()));
                }
            } else {
                return LuaValue.FALSE;
            }
        }
    }else {
        throw new LuaError("Not an inventory");
    }
}
 
开发者ID:leMaik,项目名称:RpgPlus,代码行数:22,代码来源:InventoryEventManagerImpl.java

示例12: log

import org.luaj.vm2.LuaError; //导入依赖的package包/类
@LuaFunction("log")
public void log(Varargs varargs) {
    if (varargs.narg() >= 2) {
        switch (varargs.checkjstring(1)) {
            case "info":
                plugin.getLogger().info(varargs.checkjstring(2));
                break;
            case "warn":
                plugin.getLogger().warning(varargs.checkjstring(2));
                break;
            case "error":
                plugin.getLogger().severe(varargs.checkjstring(2));
                break;
            default:
                throw new LuaError("Invalid argument, first parameter must be info, warn or error.");
        }
    } else {
        plugin.getLogger().info(varargs.checkjstring(1));
    }
}
 
开发者ID:leMaik,项目名称:RpgPlus,代码行数:21,代码来源:RpgPlusObject.java

示例13: getManagedEntity

import org.luaj.vm2.LuaError; //导入依赖的package包/类
/**
 * Get the managed entity that is represented by the given lua value.
 *
 * @param entity lua value that represents a managed entity
 * @param strict if true, a {@link LuaError} will be thrown if the entity is not a managed entity, if false, null will be returned
 * @return the managed entity or null
 * @throws LuaError if there are missing attributes or if strict is true and the entity is not a managed entity
 */
public static RpgPlusEntity getManagedEntity(LuaValue entity, boolean strict) {
    if (entity.isuserdata(Entity.class)) {
        // TODO get managed entity
        /*
        ManagedEntity managedEntity = RpgPlus.getPlugin(RpgPlus.class).getEntityManager().getEntity((Entity) CoerceLuaToJava.coerce(entity, Entity.class));
        if (managedEntity instanceof RpgPlusEntity) {
            return (RpgPlusEntity) managedEntity;
        }
        */
    } else if (entity.isuserdata(RpgPlusEntity.class)) {
        return (RpgPlusEntity) CoerceLuaToJava.coerce(entity, RpgPlusEntity.class);
    } else if (entity instanceof EntityWrapper) {
        return ((EntityWrapper) entity).getEntity();
    }

    if (strict) {
        throw new LuaError(entity + " is not a managed entity");
    } else {
        return null;
    }
}
 
开发者ID:leMaik,项目名称:RpgPlus,代码行数:30,代码来源:ScriptUtil.java

示例14: bind

import org.luaj.vm2.LuaError; //导入依赖的package包/类
/**
 * Bind a set of library functions, with an offset
 * <p>
 * An array of names is provided, and the first name is bound
 * with opcode = {@code firstopcode}, second with {@code firstopcode+1}, etc.
 * @param env The environment to apply to each bound function
 * @param factory the Class to instantiate for each bound function
 * @param names array of String names, one for each function.
 * @param firstopcode the first opcode to use
 * @see #bind(LuaValue, Class, String[])
 */
protected static void bind(LuaValue env, Class<?> factory, String[] names, int firstopcode)
{
	try
	{
		for(int i = 0, n = names.length; i < n; i++)
		{
			LibFunction f = (LibFunction)factory.newInstance();
			f._opcode = firstopcode + i;
			f._name = names[i];
			f._env = env;
			env.set(f._name, f);
		}
	}
	catch(Exception e)
	{
		throw new LuaError("bind failed: " + e);
	}
}
 
开发者ID:dwing4g,项目名称:luaj,代码行数:30,代码来源:LibFunction.java

示例15: get

import org.luaj.vm2.LuaError; //导入依赖的package包/类
@Override
public LuaValue get(LuaValue key)
{
	if(_jclass == null)
	    _jclass = JavaClass.forClass(_instance.getClass());
	Field f = _jclass.getField(key);
	if(f != null)
	    try
	    {
		    return CoerceJavaToLua.coerce(f.get(_instance));
	    }
	    catch(Exception e)
	    {
		    throw new LuaError(e);
	    }
	LuaValue m = _jclass.getMethod(key);
	if(m != null)
	    return m;
	return super.get(key);
}
 
开发者ID:dwing4g,项目名称:luaj,代码行数:21,代码来源:JavaInstance.java


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