[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ANN: LuaState (A C++ Lua Wrapper and enhanced Lua 4.1 Distribution)
- From: Roberto Ierusalimschy <rieru@...>
- Date: Fri, 9 Nov 2001 15:09:13 -0600 (CST)
On Fri, 9 Nov 2001, Edgar Toernig wrote:
> [...] Often you don't need the garbage collection
> facilities or type attributes. I.e. when you try to map C-pointers or
> numbers to Lua objects. Often this is done by casting these C types to
> a number but this will not work at all if your number type is too small.
> The only way to do this is to convert the C value to a string representa-
> tion - not very elegant.
It may not be very elegant, but it is not that ugly, either. After all,
strings in Lua are used for other "raw data" as well. A simple
lua_pushlstring(L, (char *)&pointer, sizeof(pointer));
puts the pointer into Lua, and a
pointer = *(void **)lua_tostring(L, ...)
gets it back (this is safe now in 4.1, as strings are always aligned). If
we keep your (smart) provision of not allowing those values into the Lua
program, they can be quite useful and safe.
-- Roberto