Read lua files more efficiently
... replacing horribly hacky loop.
This commit is contained in:
+7
-8
@@ -804,7 +804,7 @@ const char *fname;
|
|||||||
dlb *fh;
|
dlb *fh;
|
||||||
char *buf = (char *) 0;
|
char *buf = (char *) 0;
|
||||||
long buflen;
|
long buflen;
|
||||||
int c, llret;
|
int cnt, llret;
|
||||||
long bufidx = 0;
|
long bufidx = 0;
|
||||||
|
|
||||||
fh = dlb_fopen(fname, "r");
|
fh = dlb_fopen(fname, "r");
|
||||||
@@ -819,13 +819,12 @@ const char *fname;
|
|||||||
buf = (char *) alloc(sizeof(char) * (buflen + 1));
|
buf = (char *) alloc(sizeof(char) * (buflen + 1));
|
||||||
dlb_fseek(fh, 0L, SEEK_SET);
|
dlb_fseek(fh, 0L, SEEK_SET);
|
||||||
|
|
||||||
do {
|
if ((cnt = dlb_fread(buf, 1, buflen, fh)) != buflen) {
|
||||||
c = dlb_fgetc(fh);
|
impossible("nhl_loadlua: Error loading %s, got %i/%li bytes", fname, cnt, buflen);
|
||||||
if (c == EOF)
|
ret = FALSE;
|
||||||
break;
|
goto give_up;
|
||||||
buf[bufidx++] = (char) c;
|
}
|
||||||
} while (bufidx < buflen);
|
buf[buflen] = '\0';
|
||||||
buf[bufidx] = '\0';
|
|
||||||
(void) dlb_fclose(fh);
|
(void) dlb_fclose(fh);
|
||||||
|
|
||||||
llret = luaL_loadstring(L, buf);
|
llret = luaL_loadstring(L, buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user