lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Folks, I just went through the process of changing the typedef of
lua_Number from double to float.  My process was complicated a bit by the
use of LuaPlus, so I wanted to send a note to the list getting my
experience into the list archives so I may be able to prevent someone else
from wasting a few hours tracking down the same gotcha I found.  

Before starting, I upgraded my LuaPlus from build 1076 to 1078.  

Editting lua.h to change the typedef went smoothly.  I ended up with a
number of warnings about lost precision, but some static_cast and c-style
casts to lua_Number took care of that.  

During my initial tests I noticed that LuaPlus's LuaTableIterator was
working fine in my code, but any of LuaPlus's internal uses of
LuaTableIterator were failing after the first iteration.  In particular it
was causing GetTableCount to fail with asserts about being done too early.  
LuaTableIterator had different sizes depending on where in my project it
was created.  I've had problems like this before after merging in new
code, usually due to .NET having trouble deciding which files need to be
rebuilt when a header changes.  So, make clean; make.  Wait forever. Darn! 
Still had the issue.

It turns out that LuaPlus declares LuaObject differently depending on
whether it is used internally or externally.  Internally, LuaObject
includes a lua_TObject, and externally it includes an unsigned char[12].

The problem is that redefining lua_Number from double to float shrinks the
size of lua_TObject by 4 bytes, but, of course, doesn't shrink the 
corresponding unsigned char[12] by four bytes.  Resizing that array fixed
the problems. Hope this saves someone a little bit of trouble.


scott
--