当前位置:网站首页>[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 .
边栏推荐
- Challenges faced by virtual human industry
- 攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
- Detailed explanation of heap sort code
- LOGO特训营 第二节 文字与图形的搭配关系
- Interview essential leetcode linked list algorithm question summary, whole process dry goods!
- UML diagram memory skills
- Detailed explanation of flask context
- MYSQL架构——逻辑架构
- 好用app推荐:扫描二维码、扫描条形码并查看历史
- Now MySQL cdc2.1 is parsing the datetime class with a value of 0000-00-00 00:00:00
猜你喜欢
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
Logo special training camp Section V font structure and common design techniques
UML图记忆技巧
质量体系建设之路的分分合合
Lost in the lock world of MySQL
Redis的持久化机制
NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元
Common open source codeless testing tools
Introducing QA into the software development lifecycle is the best practice that engineers should follow
It is said that software testing is very simple, but why are there so many dissuasions?
随机推荐
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
将QA引入软件开发生命周期是工程师要遵循的最佳实践
攻防世界 MISC 进阶区 hit-the-core
Now MySQL cdc2.1 is parsing the datetime class with a value of 0000-00-00 00:00:00
攻防世界 MISC 进阶区 Ditf
Detailed explanation of flask context
Unity-VScode-Emmylua配置报错解决
Recommendation of mobile app for making barcode
Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
Google Earth Engine(GEE)——以MODIS/006/MCD19A2为例批量下载逐天AOD数据逐天的均值、最大值、最小值、标准差、方差统计分析和CSV下载(北京市各区为例)
PMO: compare the sample efficiency of 25 molecular optimization methods
通过Go语言创建CA与签发证书
醒悟的日子,我是怎么一步一步走向软件测试的道路
Li Kou 98: verify binary search tree
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
Embedded development: skills and tricks -- seven skills to improve the quality of embedded software code
SQL中MAX与GREATEST的区别
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
Naacl-22 | introduce the setting of migration learning on the prompt based text generation task
繁华落尽、物是人非:个人站长该何去何从