Пример #1
0
 public Object coerce(LuaValue value) {
   if (value.isnil()) return null;
   if (targetType == TARGET_TYPE_STRING) return value.tojstring();
   LuaString s = value.checkstring();
   byte[] b = new byte[s.m_length];
   s.copyInto(0, b, 0, b.length);
   return b;
 }
Пример #2
0
 public int score(LuaValue value) {
   switch (value.type()) {
     case LuaValue.TSTRING:
       return value.checkstring().isValidUtf8()
           ? (targetType == TARGET_TYPE_STRING ? 0 : 1)
           : (targetType == TARGET_TYPE_BYTES ? 0 : SCORE_WRONG_TYPE);
     case LuaValue.TNIL:
       return SCORE_NULL_VALUE;
     default:
       return targetType == TARGET_TYPE_STRING ? SCORE_WRONG_TYPE : SCORE_UNCOERCIBLE;
   }
 }