前面一片文章中l(wèi)ua出現(xiàn)的bug,其實(shí)是lua本身結(jié)構(gòu)問(wèn)題導(dǎo)致的:
lua中,數(shù)值使用double來(lái)存儲(chǔ),包含整形和double。而解析出來(lái)的整形也是被強(qiáng)轉(zhuǎn)為double進(jìn)行存儲(chǔ),這樣就會(huì)出問(wèn)題。
舉一個(gè)簡(jiǎn)單的例子:
double f = (double)0xffffffff;
int a = int(f);
這里的文章說(shuō)明這個(gè)類型轉(zhuǎn)換問(wèn)題的緣由。
在Squirrel腳本中就不會(huì)有這個(gè)問(wèn)題
local a = 0xffffffff
print( a )
結(jié)果為-1
查看其源代碼:
typedef union tagSQObjectValue
{
struct SQTable *pTable;
struct SQArray *pArray;
struct SQClosure *pClosure;
struct SQGenerator *pGenerator;
struct SQNativeClosure *pNativeClosure;
struct SQString *pString;
struct SQUserData *pUserData;
SQInteger nInteger;
SQFloat fFloat;
SQUserPointer pUserPointer;
struct SQFunctionProto *pFunctionProto;
struct SQRefCounted *pRefCounted;
struct SQDelegable *pDelegable;
struct SQVM *pThread;
struct SQClass *pClass;
struct SQInstance *pInstance;
struct SQWeakRef *pWeakRef;
SQRawObjectVal raw;
}SQObjectValue;
可以看到
SQInteger nInteger;
SQFloat fFloat;
是分開(kāi)存儲(chǔ)的,因此就不會(huì)有這個(gè)問(wèn)題
lua解決方法:
1. 將十六進(jìn)制換為10進(jìn)制存儲(chǔ)
2. 等待大俠或者官方修改代碼,做出patch