- Joined
- Jul 20, 2018
- Messages
- 177
I created a function to cast doubles to integers in Lua. Here is the function:
In Lua console function works as expected. Although, in WC3 the function returns complete garbage. I exported script using the editor and got this:
Why my formatted strings got replaced with some garbage?
Lua:
function cast_number(n)
local s_e_m1, m2 = string.unpack('>I4I4', string.pack('>d', n)) -- two times I4 because WC3 supports only 4-byte integers
return s_e_m1 >> 31, string.format('%03x', s_e_m1 >> 20 & 0x7ff), string.format('%05x%08x', s_e_m1 & 0xfffff, m2)
end
Lua:
function cast_number(n)
local s_e_m1, m2 = string.unpack('>I4I4', string.pack('>d', n))
return s_e_m1 >> 31, string.format('00a', s_e_m1 >> 20 & 0x7ff), string.format('b1c26af000000020', s_e_m1 & 0xfffff, m2)
end