[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: precompiling
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 15 May 2000 22:20:20 -0300 (EST)
>From: Stephen Dekorte <firstname.lastname@example.org>
>I guess I wasn't clear - I need to write out the precompiled chunk to
>a file from within lua.
>In other words, with luac I can do this:
>luac -o MyFile.luac -c MyFile.lua
>and produce a MyFile.luac file that contains a precompiled version of
>MyFile.lua. But could I do the same thing in lua without using a
But you may want to try the following function, adapted from luac.c.
int luac_dofile(FILE* D, char* filename)
FILE* f= (filename==NULL) ? stdin : fopen(filename,"r");
if (f==NULL) return 2;
if (f!=stdin) fclose(f);
I think if there's a parse error, then this code will exit the host program,
which is ok for luac but not in general.
For robust code, see lua_dofile in ldo.c.
Apart from this, the modules used by luac are written so that they can be used
by themselves -- they only need a C API such as the one above, which prepares
things and calls luaU_dumpchunk.
So, if I can come up with a clean solution for the error problem, I will add
such an API in the luac modules.
Similar code can be written for loading binary files; see luac.c.