[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Deep Copy prototype
- From: "Nick Trout" <nick@...>
- Date: Thu, 8 May 2003 11:07:17 -0700
> Of course a and b will be different.
> What Nick Trout wrote means, Lua uses the same storage for identical
strings, so it does not waste memory for several identical strings.
Although the variables may therefore refer to the same memory location,
they are still independant.
Correct. It's a little confusing, on contrary to other languages (get
out of the C mindset! :). Variables are references to objects. In the
case of strings, tables and user data variables, equal values are
pointing to the same object. In C you'd do a strcmp() to compare two
strings, which you'd expect to have different addresses. In Lua as soon
as the strings are stored, if they represent the same string, then they
*are* the same string internally! Lua has very fast hashing algorithms
to cope with strings and all objects internally. If this method of
string storage doesn't suit you it is very easy to extend Lua with a new
data type.
It might be easier to study lua_Tobject which is an instance of a Lua
typed object (although arguably clearer in Lua 4 now I look myself!):
http://www.lua.org/source/5.0/src_lobject.h.html#lua_TObject
/Nick