class LuaScriptEngine implements IScriptEngine {

    @Override
    public void compile (String scriptName, String programStr) throws ScriptLoadException {
        Log.d(SCRIPTS_TAG, "compile script '" + scriptName + "'");

        String fileDir;

        //get current script directory (required for dofile() command)
        try {
            File currentDir = FileUtils.getRelativeFile(new File(scriptName), new File("."));
            fileDir = currentDir.getPath().replace("\\", "/");

            //remove filename
            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;

        //compile
        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);
    }

    public  LuaScriptEngine();

}