lua-users home
lua-l archive

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

2012/1/10 Roberto Ierusalimschy <>:
>> If such a "external contents string" type were added to Lua, it would be
>> helpful to have an explicit "gc" callback as part of the Lua object,
>> which would get called when the Lua object was freed, and could free the
>> separate string buffer.
> It should have something like this, but we still have to figure out
> some details (for instance, whether such function could access the Lua
> state).
> -- Roberto

Hi Roberto,

I really think that a programming language should have two kinds of
string: One for Symbol and One for really string.

Symbol is used as hash-table key, flags, etc. Its just the Lua string
now. it has registered in a global string table, compared with
pointer, and has a pre-calculate hash value. its just like identify in
a language: we don't care its content, but only use it as a signature.

String is a real byte array, It can be changed, It doesn't need using
as hash-table key (but it could), It may be very long and has doesn't
need to pre-calculate a hash, compare two really string is expensive,
long String can use Copy-On-Write but it's not matter.

Now it's the balance between Symbol and String, and their using scene.

I really like string implement in nowadays lua, simple, and beautiful.
but a language should have a really mutable string. I have write a
module lbuffer[1] to implement a real string. but it can not using as
hash key and even can not compare directly.

so, maybe small string is a symbol, and bigger string is a string is a
good idea, another idea is just have two string type internal, just
like light userdata and userdata, light C function and C function,