/** Compile lua source from a Reader into a Prototype. The characters in the reader * are converted to bytes using the UTF-8 encoding, so a string literal containing * characters with codepoints 128 or above will be converted into multiple bytes. */ public Prototype compilePrototype(Reader reader, String chunkname) throws IOException { return compilePrototype(new UTF8Stream(reader), chunkname); }
/** Compile lua source from a Reader into a Prototype. The characters in the reader * are converted to bytes using the UTF-8 encoding, so a string literal containing * characters with codepoints 128 or above will be converted into multiple bytes. */ public Prototype compilePrototype(Reader reader, String chunkname) throws IOException { return compilePrototype(new UTF8Stream(reader), chunkname); }
/** Compile lua source from a Reader into a Prototype. The characters in the reader * are converted to bytes using the UTF-8 encoding, so a string literal containing * characters with codepoints 128 or above will be converted into multiple bytes. */ public Prototype compilePrototype(Reader reader, String chunkname) throws IOException { return compilePrototype(new UTF8Stream(reader), chunkname); }
private synchronized void initialize(){ Prototype binary = null; String lua; if( mClosure != null ){ return; } lua = mElement.getTextContent(); if( mLuaType == LUA_TYPE.enum_function ){ lua = "function main()" + '\n' + lua + '\n' +"end"; } try{ binary = mGlobals.compilePrototype(new ByteArrayInputStream(lua.getBytes("UTF-8")), getID()); mClosure = new LuaClosure(binary, mGlobals); mClosure.call(); } catch (Exception e){ e.printStackTrace(); } }
private Prototype loadAndCache(InputStream code, ParsedPageName chunkName) throws ScribuntoException { try { logger.debug("compiling " + chunkName); Prototype prototype = globals.compilePrototype(code, chunkName.fullPagename()); compiledScriptCache.cachePrototype(chunkName, prototype); return prototype; } catch (LuaError | IOException e) { throw new ScribuntoException(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 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; }
private LuaJScriptEngine create(KeyValueObjectCache aScene, String aScriptCode, String aMethodName) throws IOException { CacheEntry theCacheEntry = prototypes.get(aScriptCode); if (theCacheEntry == null) { Globals theGlobals = createGlobals(aScene); Prototype thePrototype = theGlobals.compilePrototype(new StringReader(aScriptCode), "script"); // Initialize the globals and the code LuaClosure theClosure = new LuaClosure(thePrototype, theGlobals); theClosure.call(); theCacheEntry = new CacheEntry(thePrototype, theGlobals); prototypes.put(aScriptCode, theCacheEntry); } return theCacheEntry.getScriptEngineFor(aScene, aMethodName); } }
binary = mGlobals.compilePrototype(streamFile, name);
binary = global.compilePrototype(streamFile, name);