当前位置:网站首页>[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 .
边栏推荐
- Logo Camp d'entraînement section 3 techniques créatives initiales
- 攻防世界 MISC 高手进阶区 001 normal_png
- LOGO特训营 第一节 鉴别Logo与Logo设计思路
- 10 schemes to ensure interface data security
- LOGO特训营 第二节 文字与图形的搭配关系
- 特征缩放 标准化 归一化
- Postgresqlql advanced skills pivot table
- 通过Go语言创建CA与签发证书
- md5工具类
- Attack and defense world misc advanced area Hong
猜你喜欢

MYSQL架构——用户权限与管理

Attack and defense world misc advanced grace-50
![[Yugong series] go teaching course 003-ide installation and basic use in July 2022](/img/65/b36ca239e06a67c01d1eb0b4648f71.png)
[Yugong series] go teaching course 003-ide installation and basic use in July 2022

Tla+ introductory tutorial (1): introduction to formal methods

蓝队攻防演练中的三段作战

Unity修仙手游 | lua动态滑动功能(3种源码具体实现)

Concurrent network modular reading notes transfer

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

With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu

攻防世界 MISC 进阶区 can_has_stdio?
随机推荐
10 schemes to ensure interface data security
Unity修仙手游 | lua动态滑动功能(3种源码具体实现)
攻防世界 misc 高手进阶区 a_good_idea
Force buckle 3_ 383. Ransom letter
Why is Dameng data called the "first share" of domestic databases?
Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集
新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码
The Sandbox 和数字好莱坞达成合作,通过人力资源开发加速创作者经济的发展
Logo special training camp Section IV importance of font design
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
页面关闭前,如何发送一个可靠请求
关于栈区、堆区、全局区、文字常量区、程序代码区
leetcode 72. Edit distance edit distance (medium)
Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
LOGO特训营 第三节 首字母创意手法
串口数据帧
PostgreSQL服务端编程聚合和分组
Concurrent optimization summary
好用app推荐:扫描二维码、扫描条形码并查看历史
Summary of index operations in mongodb