将 Lua toNumber 与 JS parseInt 进行比较 - 结果不匹配

Comparing Lua toNumber to JS parseInt - results don't match

我正在将 FiveM 的 Lua 脚本转换为 JavaScript(NodeJS 平台),我 运行 遇到了一个我无法理解的奇怪问题。

我要转换的功能很简单,它需要一个 FiveM 标识符(fivem 记录的用户的 steamid)并将其从十六进制转换为十进制。然后它将十进制值传递给 Steam 网络 API,这样我们就可以解析配置文件 name/avatar 等的 json 响应

代码本身工作正常。问题与转换有关。由于显而易见的原因,我无法 post API 密钥或 Steam ID,因此我将其空白以进行演示。

在LUA中:

local steamid = tonumber(tempSteam,16)

检索十六进制流 ID 并转换为十进制。

在 JS 中:

var steamid = parseInt(tempSteam,16);

相当于上面的JS。

奇怪的是这个。在 JS 中传入 tempSteam 导致以 ###0 结尾的 steamid,这与我以 ###6 结尾的配置文件不匹配(所有其他数字都相同)。

编辑:删掉解释内容,我后来发现(感谢评论)JS不能转换64位值。所以我现在需要找到一个解决方法。

感谢对未知信息的评论,我不知道 JS 本身不能处理 64 位数字。

我找到了解决方案,所以我将其发布在这里以防其他人遇到此问题。

NodeJS 10+ 有一个新的 BigInt 函数,可以将十六进制值转换为 64 位有符号整数。

// Our steamhex variable, this is normally pulled via FiveM's identifiers 
// so this const is just to demonstrate what it is. 
// The 0x is important, without it the BigInt function seems to fail with a 
// generic `cannot convert`.
const steamHex = '0x110000103d27e1d';

//If using fiveM use a replace i.e 
//steamHex = steamHex.replace('steam:','0x');

//Returns 76561198024392221
var result = BigInt(steamHex); 

//...pop result into your steam api call etc....