|
>>>>> "Baozeng" == Baozeng <sploving1@gmail.com> writes:
Baozeng> LuaL_dofile is ok. But sometimes users may use luaL_loadbuffer
Baozeng> to load a buffer that from a file.(There are many users, you
Baozeng> cannot decide what they do). So luaL_loadbuffer should have
Baozeng> the same behavior with luaL_loadfile.
But luaL_loadbuffer can't know whether the buffer actually came from a
file, and whether it was from the start of a file. So it makes more
sense for loadbuffer to accept only valid lua chunks, and require that
the caller handle any such details. (The other thing that dofile checks
that loadbuffer does not is whether the file starts with a BOM.)
--
Andrew.
size_t ignore_sz = 3;
if (size >= 2 && buff[0] == '#' && buff[1] == '!') {
while(ignore_sz <= size && buff[ignore_sz-1] != '\n') {
ignore_sz ++;
}
if(ignore_sz >= size) return -1;
else {
size = size - ignore_sz;
buff = buff + ignore_sz;
}
}