当前位置:网站首页>[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 .
边栏推荐
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- Business is too busy. Is there really no reason to have time for automation?
- Challenges faced by virtual human industry
- 通过Go语言创建CA与签发证书
- 高中物理:直线运动
- Erik baleog and Olaf, advanced area of misc in the attack and defense world
- PostgreSQL服务端编程聚合和分组
- md5工具类
- 攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
- Google Earth Engine(GEE)——以MODIS/006/MCD19A2为例批量下载逐天AOD数据逐天的均值、最大值、最小值、标准差、方差统计分析和CSV下载(北京市各区为例)
猜你喜欢

堆排序代码详解

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

More than 30 institutions jointly launched the digital collection industry initiative. How will it move forward in the future?

质量体系建设之路的分分合合

Mongodb aggregation operation summary

攻防世界 MISC 进阶区 Ditf

How to transfer to software testing, one of the high paying jobs in the Internet? (software testing learning roadmap attached)

Logo special training camp section III initial creative techniques

Google Earth Engine(GEE)——Tasks升级,实现RUN ALL可以一键下载任务类型中的所有影像

Embedded development: skills and tricks -- seven skills to improve the quality of embedded software code
随机推荐
Sqlserver encrypts and decrypts data
Logo special training camp Section IV importance of font design
攻防世界 MISC 进阶区 can_has_stdio?
9 - 类
Logo special training camp section 1 Identification logo and logo design ideas
制作条形码的手机App推荐
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
攻防世界 MISC 进阶区 3-11
Easy to use app recommendation: scan QR code, scan barcode and view history
With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
Google Earth Engine(GEE)——以MODIS/006/MCD19A2为例批量下载逐天AOD数据逐天的均值、最大值、最小值、标准差、方差统计分析和CSV下载(北京市各区为例)
华泰证券是国家认可的券商吗?开户安不安全?
LOGO特训营 第一节 鉴别Logo与Logo设计思路
LOGO特训营 第三节 首字母创意手法
Attack and defense world misc advanced area Hong
堆排序代码详解
Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
Business is too busy. Is there really no reason to have time for automation?
Recommendation of mobile app for making barcode
Shell 脚本实现应用服务日志入库 Mysql