Example #1
0
 public int luaCB_length(Lua l, LuaPlugin plugin) {
   try {
     l.pushNumber((double) object.length());
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   }
   return 1;
 }
Example #2
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;
 }
Example #3
0
 public int luaCB_set_length(Lua l, LuaPlugin plugin) {
   l.pushNil();
   try {
     object.setLength((long) l.checkNumber(2));
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   }
   return 1;
 }
Example #4
0
 public int luaCB_close(Lua l, LuaPlugin plugin) {
   try {
     plugin.destroyLuaObject(l);
     l.pushBoolean(true);
   } catch (IOException e) {
     l.pushBoolean(false);
     l.pushString("IOException: " + e.getMessage());
     return 2;
   }
   return 1;
 }
 public int luaCB_text(Lua l, LuaPlugin plugin) {
   try {
     plugin.generateLuaClass(l, new TextOutFile(plugin, object));
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   } catch (IllegalArgumentException e) {
     l.pushNil();
     l.pushString("Illegal argument: " + e.getMessage());
     return 2;
   }
   return 1;
 }
 public int luaCB_deflate(Lua l, LuaPlugin plugin) {
   try {
     plugin.generateLuaClass(l, new BinaryOutFile(plugin, new DeflaterOutputStream(object)));
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   } catch (IllegalArgumentException e) {
     l.pushNil();
     l.pushString("Illegal argument: " + e.getMessage());
     return 2;
   }
   return 1;
 }
 public int luaCB_four_to_five(Lua l, LuaPlugin plugin) {
   try {
     plugin.generateLuaClass(l, new BinaryOutFile(plugin, new FourToFiveEncoder(object)));
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   } catch (IllegalArgumentException e) {
     l.pushNil();
     l.pushString("Illegal argument: " + e.getMessage());
     return 2;
   }
   return 1;
 }
 public static int luaCB_open(Lua l, LuaPlugin plugin) {
   l.pushNil();
   String name = l.checkString(1);
   try {
     plugin.generateLuaClass(l, new BinaryOutFile(plugin, new FileOutputStream(name)));
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   } catch (IllegalArgumentException e) {
     l.pushNil();
     l.pushString("Illegal argument: " + e.getMessage());
     return 2;
   }
   return 1;
 }
Example #9
0
 public int luaCB_write(Lua l, LuaPlugin plugin) {
   l.pushNil();
   l.pushNil();
   try {
     long offset = (long) l.checkNumber(2);
     String towrite = l.checkString(3);
     if (towrite == "") {
       l.pushBoolean(true);
       return 1;
     }
     byte[] tmp = new byte[towrite.length()];
     object.seek(offset);
     for (int i = 0; i < towrite.length(); i++) tmp[i] = (byte) towrite.charAt(i);
     object.write(tmp);
     l.pushBoolean(true);
   } catch (IOException e) {
     l.pushBoolean(false);
     l.pushString("IOException: " + e.getMessage());
     return 2;
   }
   return 1;
 }