25 Sep 17:45
require bug?
From: Frederico Rodrigues Abraham <devotion97 <at> gmail.com>
Subject: require bug?
Newsgroups: gmane.comp.lang.lua.general
Date: 2008-09-25 15:46:38 GMT
Subject: require bug?
Newsgroups: gmane.comp.lang.lua.general
Date: 2008-09-25 15:46:38 GMT
Hi all.
I was having this strange problem with my program.
An error happened in the code: require 'corr'
Error: error loading module 'corr' from file
'app/geresim/prerock/lua/corr': cannot read
app/geresim/prerock/lua/corr: Is a directory
This error does not happen in Windows but is happening in my Linux machine.
The problem is, the 'app/geresim/prerock/lua' directory contains both a
'corr' directory and a 'corr.lua' file.
In loadlib.c, 'require' uses this 'readable' function to search
package.path for existent lua files:
332 static int readable (const char *filename) {
333 FILE *f = fopen(filename, "r"); /* try to open file */
334 if (f == NULL) return 0; /* open failed */
335 fclose(f);
336 return 1;
337 }
The problem is, apparently fopen succeeds when trying to open a
directory but later on, when the file is actually fread from, this error
happens.
I changed 'readable' so that it will fail if reading from the file fails:
332 static int readable (const char *filename) {
333 int ret = 1;
334 FILE *f = fopen(filename, "r"); /* try to open file */
335 if (f == NULL) return 0; /* open failed */
(Continue reading)
RSS Feed