[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua's symbol table
- From: Thatcher Ulrich <tu@...>
- Date: Sun, 5 Aug 2001 17:44:39 -0400 (EDT)
On Sun, 5 Aug 2001, Edgar Toernig wrote:
> > OK, I think I get this pretty well. Although if I want to keep that char*
> > valid, it doesn't appear that Lua makes any guarantees, other than that
> > lua_getref() on the locked reference will still push a valid string. It
> > seems as though the garbage collector is (and should be) still free to
> > move the actual data around.
>
> As I said, this property is not documented but in all versions of Lua
> I know (3.x, 4.x) the pointer stays the same until there's no longer
> a reference to it. Lua's garbage collector does not move data around.
>
> IMHO if you embed Lua into some application you can make use of this
> property. But if you want to take future memory management changes
> into account...
Yeah, this is something I don't want to have to think about when
upgrading. As you and lhf suggest I'll just make my own symbol table
using a Lua table, mapping new symbols to an incrementing counter. I
think that solves most of the problems. For returning the symbol name
I'll probably return a C++ string to avoid worrying about Lua's gc. That
operation is not too crucial anyway.
Thanks for the help,
-Thatcher