示例#1
0
  public static TextStyle getTextStyleArg(LuaValue val) throws ScriptException {
    TextStyle ts = val.touserdata(TextStyle.class);
    if (ts != null) {
      // The value is already a TextStyle
      return ts;
    }

    if (val.isstring()) {
      try {
        return TextStyle.fromString(val.tojstring());
      } catch (StyleParseException e) {
        throw new ScriptException("Unable to parse text style: " + val.tojstring(), e);
      }
    } else if (val.istable()) {
      LuaTable table = val.checktable();

      MutableTextStyle mts = new MutableTextStyle();
      for (LuaValue key : table.keys()) {
        ETextAttribute attribute = ETextAttribute.fromId(key.toString());
        if (attribute == null) {
          continue;
        }

        LuaValue luaValue = table.get(key);
        Object javaValue = parseTextAttribute(attribute, luaValue);
        if (javaValue != null) {
          mts.setAttribute(attribute, javaValue);
        }
      }
      return mts.immutableCopy();
    } else {
      return TextStyle.defaultInstance();
    }
  }
示例#2
0
 public static Storage toStorage(LuaTable table) throws ScriptException {
   Storage storage = new Storage();
   for (LuaValue subkey : table.keys()) {
     storage.set(subkey.tojstring(), toStoragePrimitive(table.get(subkey)));
   }
   return storage;
 }