Java Code Examples for org.luaj.vm2.LuaValue#checkfunction()

The following examples show how to use org.luaj.vm2.LuaValue#checkfunction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuaUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * parse a value to given type
 *
 * @param type
 * @param value
 * @return
 */
static Object parseValue(int type, LuaValue value) {
    switch (type) {
        case LuaValue.TBOOLEAN:
            if (isBoolean(value)) return value.checkboolean();
            break;
        case LuaValue.TNUMBER:
            if (isNumber(value)) return value.checknumber();
            break;
        case LuaValue.TSTRING:
            if (isString(value)) return value.checkjstring();
            break;
        case LuaValue.TTABLE:
            if (isTable(value)) return value.checktable();
            break;
        case LuaValue.TFUNCTION:
            if (isFunction(value)) return value.checkfunction();
            break;
        case LuaValue.TUSERDATA:
            if (isUserdata(value)) return value.checkuserdata();
            break;
        case LuaValue.TVALUE:
            return value;
    }
    return null;
}
 
Example 2
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * string.dump (function)
 * <p>
 * Returns a string containing a binary representation of the given function,
 * so that a later loadstring on this string returns a copy of the function.
 * function must be a Lua function without upvalues.
 * <p>
 * TODO: port dumping code as optional add-on
 */
static LuaValue dump(LuaValue arg) {
    LuaValue f = arg.checkfunction();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        DumpState.dump(((LuaClosure) f).p, baos, true);
        return LuaString.valueOf(baos.toByteArray());
    } catch (IOException e) {
        return error(e.getMessage());
    }
}
 
Example 3
Source File: StringLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue arg) {
	LuaValue f = arg.checkfunction();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {
		DumpState.dump( ((LuaClosure)f).p, baos, true );
		return LuaString.valueUsing(baos.toByteArray());
	} catch (IOException e) {
		return error( e.getMessage() );
	}
}
 
Example 4
Source File: StringLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public LuaValue call(LuaValue arg) {
	LuaValue f = arg.checkfunction();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {
		DumpState.dump( ((LuaClosure)f).p, baos, true );
		return LuaString.valueUsing(baos.toByteArray());
	} catch (IOException e) {
		return error( e.getMessage() );
	}
}
 
Example 5
Source File: LuaGeneration.java    From Cubes with MIT License 5 votes vote down vote up
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);
}
 
Example 6
Source File: CoroutineLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue f) {
    return new LuaThread(globals, f.checkfunction());
}
 
Example 7
Source File: CoroutineLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue f) {
    LuaValue func = f.checkfunction();
    LuaThread thread = new LuaThread(globals, func);
    return new wrapper(thread);
}
 
Example 8
Source File: CoroutineLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue f) {
	return new LuaThread(globals, f.checkfunction());
}
 
Example 9
Source File: CoroutineLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue f) {
	final LuaValue func = f.checkfunction();
	final LuaThread thread = new LuaThread(globals, func);
	return new wrapper(thread);
}
 
Example 10
Source File: CoroutineLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue call(LuaValue f) {
	return new LuaThread(globals, f.checkfunction());
}
 
Example 11
Source File: CoroutineLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue call(LuaValue f) {
	final LuaValue func = f.checkfunction();
	final LuaThread thread = new LuaThread(globals, func);
	return new wrapper(thread);
}
 
Example 12
Source File: CoroutineLib.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue call(LuaValue f) {
	return new LuaThread(globals, f.checkfunction());
}
 
Example 13
Source File: CoroutineLib.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue call(LuaValue f) {
	final LuaValue func = f.checkfunction();
	final LuaThread thread = new LuaThread(globals, func);
	return new wrapper(thread);
}
 
Example 14
Source File: LukkitCommand.java    From Lukkit with MIT License 4 votes vote down vote up
public void onTabComlete(LuaValue f) {
    tabComleteFunction = f.checkfunction();
}