lua-users home
lua-l archive

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

I'm trying to wrap a particular API function that writes a string into a 

I can call the function to tell me how long the buffer needs to be, and I can 
call it again to actually write the string:

	int length = myapi(NULL, 0);
	char* buffer = malloc(length);
	(void) myapi(buffer, length);

	lua_pushlstring(L, buffer, length);

I'd like to avoid the temporary buffer. Is there any way of persuading Lua to 
allocate an *uninitialised* string of a particular length on the stack, and 
then giving me a pointer to it so I can fill in that data one's the string's 
been allocated?

+- David Given --McQ-+ "There is nothing in the world so dangerous ---
|    | and I mean *nothing* --- as a children's story that
| ( | happens to be true." --- Master Li Kao, _The Bridge
+- --+ of Birds_

Attachment: pgp5lsxpbXB0O.pgp
Description: PGP signature