コード例 #1
0
 public int luaCB_read(Lua l, LuaPlugin plugin) {
   l.pushNil();
   l.pushNil();
   try {
     long offset = (long) l.checkNumber(2);
     int length = (int) l.checkNumber(3);
     if (length <= 0) {
       l.pushNil();
       l.pushString("Length is not positive");
       return 2;
     }
     byte[] tmp = new byte[length];
     object.seek(offset);
     length = object.read(tmp);
     if (length < 0) {
       l.pushNil();
       l.pushNil();
       return 2;
     }
     StringBuffer buf = new StringBuffer(length);
     for (byte x : tmp) buf.appendCodePoint((int) x & 0xFF);
     l.push(buf.toString());
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   }
   return 1;
 }