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

The following examples show how to use org.luaj.vm2.LuaValue#checktable() . 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: LuaConversion.java    From Cubes with MIT License 6 votes vote down vote up
public static void complexToJava(LuaValue l, Object o) {
  try {
    Field[] fields = o.getClass().getFields();
    LuaTable table = l.checktable();
    for (Field field : fields) {
      if (!(Modifier.isPublic(field.getModifiers()) || field.isAnnotationPresent(LuaInclude.class)) || field.isAnnotationPresent(LuaExclude.class))
        continue;
      if (Modifier.isFinal(field.getModifiers())) continue;
      String name = field.getName();
      Class<?> type = field.getType();
      LuaValue v = table.get(name);
      Object instance = convertToJava(type, v);
      field.set(o, instance);
    }
  } catch (Exception e) {
    Log.warning(e);
  }
}
 
Example 3
Source File: LukkitCommand.java    From Lukkit with MIT License 6 votes vote down vote up
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
    List<String> def = super.tabComplete(sender, alias, args);

    if (tabComleteFunction != null) {
        LuaValue val = tabComleteFunction.invoke(
                CoerceJavaToLua.coerce(sender),
                CoerceJavaToLua.coerce(alias),
                CoerceJavaToLua.coerce(args)
        ).arg1();
        if (val != LuaValue.NIL) {
            LuaTable tbl = val.checktable();
            Object o = Utilities.convertTable(tbl);
            if (o instanceof List)
                return (List<String>) o;
        }
    }
    return def;
}
 
Example 4
Source File: LuaEngine.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public static LuaTable moduleInstance(String module) {
	LuaValue luaModule = getEngine().call("dofile", module+".lua");

	if(luaModule.istable()) {
		return luaModule.checktable();
	}

	EventCollector.logException("failed to load instance of lua module: "+module);
	return null;
}
 
Example 5
Source File: BaseLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue index, LuaValue value) {
    LuaTable t = table.checktable();
    t.rawset(index.checknotnil(), value);
    return t;
}
 
Example 6
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue index, LuaValue value) {
	LuaTable t = table.checktable();
	t.rawset(index.checknotnil(), value);
	return t;
}
 
Example 7
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue index, LuaValue value) {
    LuaTable t = table.checktable();
    t.rawset(index.checknotnil(), value);
    return t;
}
 
Example 8
Source File: BaseLib.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue index, LuaValue value) {
	LuaTable t = table.checktable();
	if (!index.isvalidkey()) argerror(2, "table index is nil");
	t.rawset(index, value);
	return t;
}