当前位置:网站首页>[Lua] Int64 support
[Lua] Int64 support
2022-07-04 22:40:00 【Rice shrimp】
In the previous version ,lua Only by default double type , Although it can be modified luaconf.h The definition in lua number Change it to int64, But for int64 Type abandonment double Obviously not , Belong to attend to one thing and lose the other .
that , about 64bit There are many solutions for , The basic idea is to use 8bytes Of string / lightuserdata / userdata Modify the meta table to realize .
We In general use 8bytes Long string To represent a int64 . This can be the only key use , Without complex extensions , It belongs to a better way .
If you want to deal with it directly in the project 64bit Of timestamp. It needs to be right int64 Do mathematical operations . stay luajit in , I defined one userdata And overload its operator to complete . You can use ffi.cast("int64_t",0) To construct a 64bit Of 0. For this practice , Let's not talk about userdata The extra cost of , One problem with this is When 64bit Of cdata do table Of key When , Of the same value int64 It's not the same key .
therefore , There is a lighter way to solve int64 The question of support . That is in 64 A platform , We can use it lightuserdata No loss means a int64, By giving lightuserdata Set up metatable , We can take over its data operations . The only drawback is , Compare one int64 And ordinary lua number Is it equal ,lua You can't convert implicitly ( Greater than less than comparison is no problem ).
thus , It took Fengyun a little time to build a library . This library only provides an explicit api , That is to construct a int64 Numbers . It can be downloaded from lua number structure , Also support from a 8 Byte wide string with small header . What is actually stored in memory is a lightuserdata That is, a 64bit The pointer ( So this library is not applicable to 32 Bit platform ). It can also be done through C Interface lua_pushlightuserdata Let's take one 64bit Integer push on stack .
hold int64 Convert to normal lua number Borrowed # The operator .
边栏推荐
猜你喜欢
页面关闭前,如何发送一个可靠请求

Detailed explanation of heap sort code

MYSQL架构——逻辑架构

业务太忙,真的是没时间搞自动化理由吗?

It is said that software testing is very simple, but why are there so many dissuasions?

都说软件测试很简单有手就行,但为何仍有这么多劝退的?

达梦数据凭什么被称为国产数据库“第一股”?

Hit the core in the advanced area of misc in the attack and defense world

The Sandbox 和数字好莱坞达成合作,通过人力资源开发加速创作者经济的发展

Li Kou 98: verify binary search tree
随机推荐
leetcode 72. Edit Distance 编辑距离(中等)
不同环境相同配置项的内容如何diff差异?
About stack area, heap area, global area, text constant area and program code area
攻防世界 misc 高手进阶区 a_good_idea
Shell script implements application service log warehousing MySQL
LOGO特訓營 第一節 鑒別Logo與Logo設計思路
Unity修仙手游 | lua动态滑动功能(3种源码具体实现)
繁华落尽、物是人非:个人站长该何去何从
leetcode 72. Edit distance edit distance (medium)
Mysql root 账号如何重置密码
It is said that software testing is very simple, but why are there so many dissuasions?
Concurrent network modular reading notes transfer
Google Earth Engine(GEE)——Tasks升级,实现RUN ALL可以一键下载任务类型中的所有影像
Lost in the lock world of MySQL
Logo special training camp Section IV importance of font design
攻防世界 MISC 进阶区 hit-the-core
PMO: compare the sample efficiency of 25 molecular optimization methods
Why is Dameng data called the "first share" of domestic databases?
PostgreSQL server programming aggregation and grouping
【lua】int64的支持