@Test public void testCompile () throws ScriptLoadException { LuaScriptEngine engine = new LuaScriptEngine(); engine.compile("test", "return test()"); }
@Override public void compile (String scriptName, String programStr) throws ScriptLoadException { Log.d(SCRIPTS_TAG, "compile script '" + scriptName + "'"); String fileDir; try { File currentDir = FileUtils.getRelativeFile(new File(scriptName), new File(".")); fileDir = currentDir.getPath().replace("\\", "/"); fileDir = fileDir.substring(0, fileDir.lastIndexOf('/') + 1); } catch (IOException e) { Log.w(SCRIPTS_TAG, "IOException while getting current relative file path of lua script: ", e); throw new ScriptLoadException("IOException while loading script: ", e); } programStr = "--define global variable for relative dir path\nrelDir = \"" + fileDir + "\"; " + programStr; ChunkLoader loader = CompilerChunkLoader.of("engine"); LuaFunction func = null; try { func = loader.loadTextChunk(new Variable(env), scriptName, programStr); } catch (LoaderException e) { Log.e(SCRIPTS_TAG, "Couldn't compile lua script: " + programStr + ", error: " + e.getLuaStyleErrorMessage(), e); throw new ScriptLoadException("Coulnd't compile script: " + programStr + ", error: " + e.getLuaStyleErrorMessage()); } this.luaFunctions.put(scriptName, func); }
LuaScriptEngine implements IScriptEngine { @Override public void compile (String scriptName, String programStr) throws ScriptLoadException { Log.d(SCRIPTS_TAG, "compile script '" + scriptName + "'"); String fileDir; try { File currentDir = FileUtils.getRelativeFile(new File(scriptName), new File(".")); fileDir = currentDir.getPath().replace("\\", "/"); fileDir = fileDir.substring(0, fileDir.lastIndexOf('/') + 1); } catch (IOException e) { Log.w(SCRIPTS_TAG, "IOException while getting current relative file path of lua script: ", e); throw new ScriptLoadException("IOException while loading script: ", e); } programStr = "--define global variable for relative dir path\nrelDir = \"" + fileDir + "\"; " + programStr; ChunkLoader loader = CompilerChunkLoader.of("engine"); LuaFunction func = null; try { func = loader.loadTextChunk(new Variable(env), scriptName, programStr); } catch (LoaderException e) { Log.e(SCRIPTS_TAG, "Couldn't compile lua script: " + programStr + ", error: " + e.getLuaStyleErrorMessage(), e); throw new ScriptLoadException("Coulnd't compile script: " + programStr + ", error: " + e.getLuaStyleErrorMessage()); } this.luaFunctions.put(scriptName, func); } }
LuaScriptEngine implements IScriptEngine { @Override public void compile (String scriptName, String programStr) throws ScriptLoadException { Log.d(SCRIPTS_TAG, "compile script '" + scriptName + "'"); String fileDir; try { File currentDir = FileUtils.getRelativeFile(new File(scriptName), new File(".")); fileDir = currentDir.getPath().replace("\\", "/"); fileDir = fileDir.substring(0, fileDir.lastIndexOf('/') + 1); } catch (IOException e) { Log.w(SCRIPTS_TAG, "IOException while getting current relative file path of lua script: ", e); throw new ScriptLoadException("IOException while loading script: ", e); } programStr = "--define global variable for relative dir path\nrelDir = \"" + fileDir + "\"; " + programStr; ChunkLoader loader = CompilerChunkLoader.of("engine"); LuaFunction func = null; try { func = loader.loadTextChunk(new Variable(env), scriptName, programStr); } catch (LoaderException e) { Log.e(SCRIPTS_TAG, "Couldn't compile lua script: " + programStr + ", error: " + e.getLuaStyleErrorMessage(), e); throw new ScriptLoadException("Coulnd't compile script: " + programStr + ", error: " + e.getLuaStyleErrorMessage()); } this.luaFunctions.put(scriptName, func); } LuaScriptEngine(); }
LuaScriptEngine implements IScriptEngine { @Override public void compile (String scriptName, String programStr) throws ScriptLoadException { Log.d(SCRIPTS_TAG, "compile script '" + scriptName + "'"); String fileDir; try { File currentDir = FileUtils.getRelativeFile(new File(scriptName), new File(".")); fileDir = currentDir.getPath().replace("\\", "/"); fileDir = fileDir.substring(0, fileDir.lastIndexOf('/') + 1); } catch (IOException e) { Log.w(SCRIPTS_TAG, "IOException while getting current relative file path of lua script: ", e); throw new ScriptLoadException("IOException while loading script: ", e); } programStr = "--define global variable for relative dir path\nrelDir = \"" + fileDir + "\"; " + programStr; ChunkLoader loader = CompilerChunkLoader.of("engine"); LuaFunction func = null; try { func = loader.loadTextChunk(new Variable(env), scriptName, programStr); } catch (LoaderException e) { Log.e(SCRIPTS_TAG, "Couldn't compile lua script: " + programStr + ", error: " + e.getLuaStyleErrorMessage(), e); throw new ScriptLoadException("Coulnd't compile script: " + programStr + ", error: " + e.getLuaStyleErrorMessage()); } this.luaFunctions.put(scriptName, func); } LuaScriptEngine(); @Override void compile(String scriptName, String programStr); @Override void loadFile(File file); @Override Object execFunc(String funcName, Object... args); @Override Object execFunc(String funcName); @Override Object execScript(String scriptName, Object... args); @Override void shutdown(); }
LuaScriptEngine implements IScriptEngine { @Override public void compile (String scriptName, String programStr) throws ScriptLoadException { Log.d(SCRIPTS_TAG, "compile script '" + scriptName + "'"); String fileDir; try { File currentDir = FileUtils.getRelativeFile(new File(scriptName), new File(".")); fileDir = currentDir.getPath().replace("\\", "/"); fileDir = fileDir.substring(0, fileDir.lastIndexOf('/') + 1); } catch (IOException e) { Log.w(SCRIPTS_TAG, "IOException while getting current relative file path of lua script: ", e); throw new ScriptLoadException("IOException while loading script: ", e); } programStr = "--define global variable for relative dir path\nrelDir = \"" + fileDir + "\"; " + programStr; ChunkLoader loader = CompilerChunkLoader.of("engine"); LuaFunction func = null; try { func = loader.loadTextChunk(new Variable(env), scriptName, programStr); } catch (LoaderException e) { Log.e(SCRIPTS_TAG, "Couldn't compile lua script: " + programStr + ", error: " + e.getLuaStyleErrorMessage(), e); throw new ScriptLoadException("Coulnd't compile script: " + programStr + ", error: " + e.getLuaStyleErrorMessage()); } this.luaFunctions.put(scriptName, func); } LuaScriptEngine(); @Override void compile(String scriptName, String programStr); @Override void loadFile(File file); @Override Object execFunc(String funcName, Object... args); @Override Object execFunc(String funcName); @Override Object execScript(String scriptName, Object... args); @Override void shutdown();  }