[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Manipulating locals
- From: virgil@... (Virgil Smith)
- Date: Thu, 21 Aug 2003 18:16:43 -0500
No, my comment was that if you wish to inject additional script code into a
chunk using a ChunkReader function passed to lua_load you may have to know
whether to inject strings or bytecodes. The reason I say this is that
lua_load automatically detects the format of the code, but I do not know if
it can handle a switch in mid-load.
for instance if you write the following (correcting any errors in it)...
typedef struct _ReadState
const char *Prefix;
const char *Suffix;
const char *MyChunkReader(lua_State *L, void *data, size_t *Size)
ReadState *State = (ReadState *)data;
*Size = strlen(State->Prefix);
/* insert boring code here to read from the file */
*Size = strlen(State->Suffix);
*Size = 0;
MyData.Prefix = "local SomeLocal;";
MyData.Suffix = NULL;
MyData.Stage = 0;
MyData.File = fopen("SomeScript.lua", "r");
lua_load(L, MyChunkReader, &MyData, "This is an example");
Then the string "local SomeLocal;" will be injected into the chunk before
the contents of the file "SomeScript.lua". If "SomeScript.lua" contains
ANSI textual Lua code then this is no problem. If, however, it contains
precompiled byte code then lua_load might become confused when the chunk
switches from ANSI to byte code in mid-stream.
[mailto:email@example.com]On Behalf Of D Burgess
Sent: Thursday, August 21, 2003 5:24 PM
To: Lua list
Subject: Re: Manipulating locals
>Virgil Smith said
> <other stuff> side issue here is that
>you may have to restrict the string/file/whatever to only contain textual
>(i.e. non-precompiled) script code, otherwise you will have to figure out
>how to generate bytecode that isn't already chunked.
Are we saying that compiled script is scoped differently?