lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, 2003-02-18 at 12:31, phil@flamewars.org wrote:
> I'm designing a binary file format, and I'd like to be able to embed byte-compiled 
> Lua chunks in it. I looked in the refman, but I wasn't able to find anything on it. 
> So, can I store byte-compiled chunks in null-terminated C strings? Specifically, 
> will there be any stray nulls in a byte-compiled chunk?
> 

This definitely won't work; if you're storing a binary file, you could
store a length field and then the bytes.  Null-terminated definitely
won't work tho.  For binary files, even for normal strings it's probably
better to put the size of the string first, since it makes parsing and
loading the file a lot more efficient (since you can allocate the
necessary space up front and just read() the bytes into it).

> Thanks, Philip Bock
-- 
Sean Middleditch <elanthis@awesomeplay.com>