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(); } }
public boolean load(Globals globals, String name, Object... args){ LuaClosure closure = null; if( RapidStringUtils.isEmpty(name) || globals == null ){ return false; } try{ closure = getClosure(globals, name); if( args.length == 0 ){ closure.call(); } else if( args.length == 1 ){ closure.call( args[0] instanceof LuaValue ? (LuaValue) args[0] : CoerceJavaToLua.coerce(args[0]) ); } else if( args.length == 2 ){ closure.call( args[0] instanceof LuaValue ? (LuaValue) args[0] : CoerceJavaToLua.coerce(args[0]), args[1] instanceof LuaValue ? (LuaValue) args[1] : CoerceJavaToLua.coerce(args[1]) ); } else{ closure.call( args[0] instanceof LuaValue ? (LuaValue) args[0] : CoerceJavaToLua.coerce(args[0]), args[1] instanceof LuaValue ? (LuaValue) args[1] : CoerceJavaToLua.coerce(args[1]), args[2] instanceof LuaValue ? (LuaValue) args[2] : CoerceJavaToLua.coerce(args[2]) ); } } catch (Exception e){ e.printStackTrace(); } return true; }
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); } }
public boolean load(RapidLuaEnvironment luaEnv, String name, Object... args){ LuaClosure closure = null; if( RapidStringUtils.isEmpty(name) || luaEnv == null ){ return false; } try{ closure = luaEnv.getClosure(name); if( args.length == 0 ){ closure.call(); } else if( args.length == 1 ){ closure.call( args[0] instanceof LuaValue ? (LuaValue) args[0] : CoerceJavaToLua.coerce(args[0]) ); } else if( args.length == 2 ){ closure.call( args[0] instanceof LuaValue ? (LuaValue) args[0] : CoerceJavaToLua.coerce(args[0]), args[1] instanceof LuaValue ? (LuaValue) args[1] : CoerceJavaToLua.coerce(args[1]) ); } else{ closure.call( args[0] instanceof LuaValue ? (LuaValue) args[0] : CoerceJavaToLua.coerce(args[0]), args[1] instanceof LuaValue ? (LuaValue) args[1] : CoerceJavaToLua.coerce(args[1]), args[2] instanceof LuaValue ? (LuaValue) args[2] : CoerceJavaToLua.coerce(args[2]) ); } } catch (Exception e){ e.printStackTrace(); } return true; } public boolean load(Globals globals, String name, Object... args){
closure.call();
closure.call();