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 
buffer.

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);
	free(buffer);
}

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 ---
|  dg@cowlark.com    | and I mean *nothing* --- as a children's story that
| (dg@tao-group.com) | happens to be true." --- Master Li Kao, _The Bridge
+- www.cowlark.com --+ of Birds_

Attachment: pgpv8ECjTENEz.pgp
Description: PGP signature