lua-users home
lua-l archive

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


Hi Tobias

That raises an interesting question.  Currently I have a couple of
ways to create a Buffer( not the segment ), and they are inconsistent:

b  = Buffer( 1024 ) -- empty Buffer with 1024 bytes
s  = 'This is some example content'
b1 = Buffer( s )    -- buffer filled with s, #b1 == #s
b2 = Buffer( b1 )   -- buffer filled with content of b1; #b1 == #b2
                    -- this is a true clone, not a reference
If it is a clone, why don't you provide a method for it:

b2 = b1:clone()

sg = b1:Segment( 1, 5) -- Segment[1:5]; #sg == 5
b3 = Buffer( sg )   -- buffer with content of sg, #b3 == #sg
                    -- true clone of content
Since b3 is not a Segment, it is not a clone, isn't it? I would call it differently:

b3 = sg:buffer() -- or sg:newbuffer() or something else...

b4 = Buffer(14, b1) -- buffer with first 14 bytes from b1
This is another clone isn't it?  Then name it clone!

b4 = b1:clonefirst (14) -- clone b1 from 1 to 14
b5 = b1:clonefrom (14) -- clone b1 from 14 to the end

As you can see the arguments are inconsistent;
either (number, content) or (number) or (content)
Any ideas how to reconcile that?
b6 = b1:clone (init, end) -- This seems to be more general; default: (1, #b1)

Regards,
Tomás