cdata concatenation

  • From: Egor Skriptunoff <egor.skriptunoff@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 8 May 2020 14:03:05 +0300

I've found a ... strange feature in LuaJIT.
It appears some cdata values are allowed to be concatenated, but the result
is random:

= 1LL .. 2LL
1077850264LL
= bit.tohex(1LL .. 2LL)
fffffffb403f7700
= 1LL .. 2LL
4629545966695838599LL
= 1LL .. 2LL
112LL
= 1LL .. 2LL
202LL
= 1LL .. 2LL
1077869360LL
= 1LL .. 2LL
42LL
= 1LL .. 2LL
1077894976LL
= 0LL .. 0LL
4629474467297361920LL
= 0LL .. 0LL
4629529259273053269LL
= 0LL .. 0LL
585LL
= 0LL .. 0LL
33LL
= 0LL .. 0LL
1077856728LL
= 0LL .. 0LL
0LL
= 0LL .. 0LL
1077902088LL
= 0LL .. 0LL
136LL
= 0LL .. 0LL
178114797612LL
= 0LL .. 0LL
1077850296LL
= 0LL .. 0LL
1077850296LL
= 0LL .. 0LL
1077850296LL
= 0LL .. 0LL
1077850376LL
= 0LL .. 0LL
0LL
= 0LL .. 0LL
0LL


BTW, some cdata are not allowed to be concatenated, for example, string
pointers:

xx, yy = "abc", "def"  -- anchors
x=ffi.new("const char *", xx)
y=ffi.new("const char *", yy)
z=x..y
stdin:1: attempt to concatenate 'const char *' and 'const char *'
stack traceback:
    stdin:1: in main chunk
    [C]: at 0x004048f0
z=x.."def"
stdin:1: attempt to concatenate 'const char *' and 'string'
stack traceback:
    stdin:1: in main chunk
    [C]: at 0x004048f0


What cdata concatenation was introduced for?
For what types cdata concatenation gives meaningful result (without
metatypes)?

Other related posts: