/** Compile lua source from an InputStream into a Prototype. * The input is assumed to be UTf-8, but since bytes in the range 128-255 are passed along as * literal bytes, any ASCII-compatible encoding such as ISO 8859-1 may also be used. */ public Prototype compilePrototype(InputStream stream, String chunkname) throws IOException { if (compiler == null) error("No compiler."); return compiler.compile(stream, chunkname); }
/** Compile lua source from an InputStream into a Prototype. * The input is assumed to be UTf-8, but since bytes in the range 128-255 are passed along as * literal bytes, any ASCII-compatible encoding such as ISO 8859-1 may also be used. */ public Prototype compilePrototype(InputStream stream, String chunkname) throws IOException { if (compiler == null) error("No compiler."); return compiler.compile(stream, chunkname); }
/** Compile lua source from an InputStream into a Prototype. * The input is assumed to be UTf-8, but since bytes in the range 128-255 are passed along as * literal bytes, any ASCII-compatible encoding such as ISO 8859-1 may also be used. */ public Prototype compilePrototype(InputStream stream, String chunkname) throws IOException { if (compiler == null) error("No compiler."); return compiler.compile(stream, chunkname); }
/** Load lua source or lua binary from an input stream into a Prototype. * The InputStream is either a binary lua chunk starting with the lua binary chunk signature, * or a text input file. If it is a text input file, it is interpreted as a UTF-8 byte sequence. * @param is Input stream containing a lua script or compiled lua" * @param chunkname Name that will be used within the chunk as the source. * @param mode String containing 'b' or 't' or both to control loading as binary or text or either. */ public Prototype loadPrototype(InputStream is, String chunkname, String mode) throws IOException { if (mode.indexOf('b') >= 0) { if (undumper == null) error("No undumper."); if (!is.markSupported()) is = new BufferedStream(is); is.mark(4); final Prototype p = undumper.undump(is, chunkname); if (p != null) return p; is.reset(); } if (mode.indexOf('t') >= 0) { return compilePrototype(is, chunkname); } error("Failed to load prototype "+chunkname+" using mode '"+mode+"'"); return null; }
/** Convenience function for loading a file that is either binary lua or lua source. * @param filename Name of the file to load. * @return LuaValue that can be call()'ed or invoke()'ed. * @throws LuaError if the file could not be loaded. */ public LuaValue loadfile(String filename) { try { return load(finder.findResource(filename), "@"+filename, "bt", this); } catch (Exception e) { return error("load "+filename+": "+e); } }
/** Convenience function for loading a file that is either binary lua or lua source. * @param filename Name of the file to load. * @return LuaValue that can be call()'ed or invoke()'ed. * @throws LuaError if the file could not be loaded. */ public LuaValue loadfile(String filename) { try { return load(finder.findResource(filename), "@"+filename, "bt", this); } catch (Exception e) { return error("load "+filename+": "+e); } }
/** Load lua source or lua binary from an input stream into a Prototype. * The InputStream is either a binary lua chunk starting with the lua binary chunk signature, * or a text input file. If it is a text input file, it is interpreted as a UTF-8 byte sequence. * @param is Input stream containing a lua script or compiled lua" * @param chunkname Name that will be used within the chunk as the source. * @param mode String containing 'b' or 't' or both to control loading as binary or text or either. */ public Prototype loadPrototype(InputStream is, String chunkname, String mode) throws IOException { if (mode.indexOf('b') >= 0) { if (undumper == null) error("No undumper."); if (!is.markSupported()) is = new BufferedStream(is); is.mark(4); final Prototype p = undumper.undump(is, chunkname); if (p != null) return p; is.reset(); } if (mode.indexOf('t') >= 0) { return compilePrototype(is, chunkname); } error("Failed to load prototype "+chunkname+" using mode '"+mode+"'"); return null; }
/** Load the content form an input stream as a binary chunk or text file. * @param is InputStream containing a lua script or compiled lua" * @param chunkname Name that will be used within the chunk as the source. * @param mode String containing 'b' or 't' or both to control loading as binary or text or either. * @param environment LuaTable to be used as the environment for the loaded function. * */ public LuaValue load(InputStream is, String chunkname, String mode, LuaValue environment) { try { Prototype p = loadPrototype(is, chunkname, mode); return loader.load(p, chunkname, environment); } catch (LuaError l) { throw l; } catch (Exception e) { return error("load "+chunkname+": "+e); } }
/** Load the content form an input stream as a binary chunk or text file. * @param is InputStream containing a lua script or compiled lua" * @param chunkname Name that will be used within the chunk as the source. * @param mode String containing 'b' or 't' or both to control loading as binary or text or either. * @param environment LuaTable to be used as the environment for the loaded function. * */ public LuaValue load(InputStream is, String chunkname, String mode, LuaValue environment) { try { Prototype p = loadPrototype(is, chunkname, mode); return loader.load(p, chunkname, environment); } catch (LuaError l) { throw l; } catch (Exception e) { return error("load "+chunkname+": "+e); } }