lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


No, I think not (without patching the Lua C/API, that is).

David Given kirjoitti 2.2.2006 kello 19.44:

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_

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Darwin)

iD8DBQFD5OioGJtHlJZfjQoRAoYIAJ9ltk84TektK/0iBo6YJi1/QLUoCgCfZ0Ad
FBh1EQYUFlu4ZZK7l0iAf+s=
=vOdW
-----END PGP SIGNATURE-----