Tolua Example 16 TestInt64

 

    string script =

        @"           

            function TestInt64(x)               

                x = 789 + x

                assert(tostring(x) == '9223372036854775807')                                            

                local low, high = int64.tonum2(x)      --分成高低位两部分         

                print('x value is: '..tostring(x)..' low is: '.. low .. ' high is: '..high.. ' type is: '.. tolua.typename(x))          

                local y = int64.new(1,2)         --new 一个低位为1高位为264位值      

                local z = int64.new(1,2)

               

                if y == z then                  --两个64位的比较

                    print('int64 equals is ok, value: '..int64.tostring(y)) --int64.tostring

                end

 

                x = int64.new(123)                   --new一个只有低位的

           

                if int64.equals(x, 123) then

                    print('int64 equals to number ok')

                else

                    print('int64 equals to number failed')

                end

 

                x = int64.new('78962871035984074')  --直接在lua调用int64.new,生成一个64int

                print('int64 is: '..tostring(x))

 

                local str = tostring(int64.new(3605690779, 30459971))               

                local n2 = int64.new(str)

                local l, h = int64.tonum2(n2)                       

                print(str..':'..tostring(n2)..' low:'..l..' high:'..h)                 

 

                print('----------------------------uint64-----------------------------')

                x = uint64.new('18446744073709551615')                                

                print('uint64 max is: '..tostring(x))

                l, h = uint64.tonum2(x)     

                str = tostring(uint64.new(l, h))

                print(str..':'..tostring(x)..' low:'..l..' high:'..h)    

 

                return y

            end

        ";

 

 

 

 

Lua 5.1不支持64int

tolua使用的是lua 5.1

因为tolua使用luajit,luajit 5.1之后就不升级了

所以tolua只能自己实现int64

你可能感兴趣的:(lua,unity)