lua-users home
lua-l archive

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


2012/1/11 Dirk Laurie <dirk.laurie@gmail.com>:
>>>
>>> Is there going to be syntax for constructing "really string" literals?
>>> If not, it can be implemented as a library operating on userdata,
>>> rather like the `file:` functions.
>>>
>>> Which metamethods should it have?
>>>
>>> len, concat: like string
>>> eq, le, lt: actual comparisons
>>> add: bitwise `or`
>>> sub: bitwise `nor`
>>> mul: bitwise `and`
>>> div: bitwise `nand`
>>> unm: bitwise `not`
>>> index: access to a byte
>>> newindex: changing a byte
>>
>> If two string is not same length, then how to define these binary operations?
>>
> Two possiblities:
>
>  - it is an error
>  - the shorter string defines the length of the result
>
> Which do you prefer?
>

I think error is better, and, when I try to implement this function, I
found that should we create a new string for calculate result? I think
its not good :-(

if you use my module lbuffer[1], you can get anything other than
binary operations. and you can do this yourself:
for i = 1, 32 do
   s1[i] = bit32.band(s1[i], s2[i], s3[i], s4[i])
end
print(s1)

[1]: https://github.com/starwing/lbuffer