diff options
Diffstat (limited to 'src/lib/elua')
-rw-r--r-- | src/lib/elua/cache.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/lib/elua/cache.c b/src/lib/elua/cache.c index fe6825f0f9..91fcdac658 100644 --- a/src/lib/elua/cache.c +++ b/src/lib/elua/cache.c | |||
@@ -35,11 +35,11 @@ generate: | |||
35 | } | 35 | } |
36 | 36 | ||
37 | static Eina_File * | 37 | static Eina_File * |
38 | open_src(const char *fname, Eina_Bool *bc) | 38 | open_src(const char *fname, Eina_Bool *bc, Eina_Bool allow_bc) |
39 | { | 39 | { |
40 | Eina_File *f = NULL; | 40 | Eina_File *f = NULL; |
41 | const char *ext = strstr(fname, ".lua"); | 41 | const char *ext = strstr(fname, ".lua"); |
42 | if (ext && !ext[4]) | 42 | if (ext && !ext[4] && allow_bc) |
43 | { | 43 | { |
44 | char buf[PATH_MAX]; | 44 | char buf[PATH_MAX]; |
45 | snprintf(buf, sizeof(buf), "%sc", fname); | 45 | snprintf(buf, sizeof(buf), "%sc", fname); |
@@ -151,7 +151,7 @@ elua_io_loadfile(const Elua_State *es, const char *fname) | |||
151 | { | 151 | { |
152 | return elua_loadstdin(L); | 152 | return elua_loadstdin(L); |
153 | } | 153 | } |
154 | if (!(f = open_src(fname, &bcache))) | 154 | if (!(f = open_src(fname, &bcache, EINA_TRUE))) |
155 | { | 155 | { |
156 | lua_pushfstring(L, "cannot open %s: %s", fname, strerror(errno)); | 156 | lua_pushfstring(L, "cannot open %s: %s", fname, strerror(errno)); |
157 | return LUA_ERRFILE; | 157 | return LUA_ERRFILE; |
@@ -167,7 +167,37 @@ elua_io_loadfile(const Elua_State *es, const char *fname) | |||
167 | status = lua_load(L, getf_map, &s, chname); | 167 | status = lua_load(L, getf_map, &s, chname); |
168 | eina_file_map_free(f, s.fmap); | 168 | eina_file_map_free(f, s.fmap); |
169 | eina_file_close(f); | 169 | eina_file_close(f); |
170 | if (!status && bcache) write_bc(L, fname); | 170 | if (status) |
171 | { | ||
172 | /* we loaded bytecode and that failed; try loading source instead */ | ||
173 | if (!bcache) | ||
174 | { | ||
175 | /* can't open real file, so return original error */ | ||
176 | if (!(f = open_src(fname, &bcache, EINA_FALSE))) | ||
177 | { | ||
178 | lua_remove(L, -2); | ||
179 | return status; | ||
180 | } | ||
181 | s.flen = eina_file_size_get(f); | ||
182 | /* can't read real file, so return original error */ | ||
183 | if (!(s.fmap = eina_file_map_all(f, EINA_FILE_RANDOM))) | ||
184 | { | ||
185 | lua_remove(L, -2); | ||
186 | return status; | ||
187 | } | ||
188 | /* loaded original file, pop old error and load again */ | ||
189 | lua_pop(L, 1); | ||
190 | status = lua_load(L, getf_map, &s, chname); | ||
191 | eina_file_map_free(f, s.fmap); | ||
192 | eina_file_close(f); | ||
193 | /* force write new bytecode */ | ||
194 | if (!status) | ||
195 | write_bc(L, fname); | ||
196 | } | ||
197 | /* whatever happened here, proceed to the end... */ | ||
198 | } | ||
199 | else if (bcache) | ||
200 | write_bc(L, fname); /* success and bytecode write */ | ||
171 | lua_remove(L, -2); | 201 | lua_remove(L, -2); |
172 | return status; | 202 | return status; |
173 | } | 203 | } |