@@ -498,7 +498,53 @@ do -- getp/setp
498498 local a = {}
499499 T .testC (" rawsetp 2 1" , a , 20 )
500500 assert (a [T .pushuserdata (1 )] == 20 )
501- assert (T .testC (" rawgetp 2 1; return 1" , a ) == 20 )
501+ assert (T .testC (" rawgetp -1 1; return 1" , a ) == 20 )
502+ end
503+
504+
505+ do -- using the table itself as index
506+ local a = {}
507+ a [a ] = 10
508+ local prog = " gettable -1; return *"
509+ local res = {T .testC (prog , a )}
510+ assert (# res == 2 and res [1 ] == prog and res [2 ] == 10 )
511+
512+ local prog = " settable -2; return *"
513+ local res = {T .testC (prog , a , 20 )}
514+ assert (a [a ] == 20 )
515+ assert (# res == 1 and res [1 ] == prog )
516+
517+ -- raw
518+ a [a ] = 10
519+ local prog = " rawget -1; return *"
520+ local res = {T .testC (prog , a )}
521+ assert (# res == 2 and res [1 ] == prog and res [2 ] == 10 )
522+
523+ local prog = " rawset -2; return *"
524+ local res = {T .testC (prog , a , 20 )}
525+ assert (a [a ] == 20 )
526+ assert (# res == 1 and res [1 ] == prog )
527+
528+ -- using the table as the value to set
529+ local prog = " rawset -1; return *"
530+ local res = {T .testC (prog , 30 , a )}
531+ assert (a [30 ] == a )
532+ assert (# res == 1 and res [1 ] == prog )
533+
534+ local prog = " settable -1; return *"
535+ local res = {T .testC (prog , 40 , a )}
536+ assert (a [40 ] == a )
537+ assert (# res == 1 and res [1 ] == prog )
538+
539+ local prog = " rawseti -1 100; return *"
540+ local res = {T .testC (prog , a )}
541+ assert (a [100 ] == a )
542+ assert (# res == 1 and res [1 ] == prog )
543+
544+ local prog = " seti -1 200; return *"
545+ local res = {T .testC (prog , a )}
546+ assert (a [200 ] == a )
547+ assert (# res == 1 and res [1 ] == prog )
502548end
503549
504550a = {x = 0 , y = 12 }
0 commit comments