lua-users home
lua-l archive

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



If you mean allocating a buffer where the data is read (by C) and using it then in Lua, why not simply give a proper userdata block length (you can use a structure with 'data[0]' as a "growing tail" in most compilers). Then, you'd attack __index metamethod to the userdata so it seems like a usual Lua (read-only) table to Lua scripts. Would this be enough?

Other alternative (since it's char*) would be pushing a specific length string, but this might need an interim buffer malloced/freed by you (since Lua strings are read-only).

Did I even touch close? :)

btw, Why is the iMaxSize a reference (you're using C++ here, right?). That is, is the 'Read' function actually setting/writing it, is it input only, or mixed input-output. Please specify.

-ak

30.4.2005 kello 13:26, Robert Aronsson kirjoitti:

 Hi guys,

Excuse me if this has been posted before but I cant find it in the archives.

I need to call a c function from lua that looks like this

bool Read(char *pData,unsigned int &iMaxSize);

The Read function will read some data of max iMaxSize and place it in
the pre-allocated pData char pointer, returns true on success or false
on failure.

My question is, how do I pre-allocate an array in Lua that I can use
to send into this C function? (without doing a for loop that adds
strings to a variable for example)

Best Regards,
Robert Aronsson