|
On 29 Jun 2006, at 11:34, D Burgess wrote:
Carsten Fuchs wrote: [...]I guess that the conversion to a string means that the string has to belua_tostring() from my code. However, I'm wondering why lua_tostring() behaves in this (somewhatsurprising) manner? This makes it different from all the other lua_to*()functions, and I wonder why this is so??allocated and stored somewhere. Numbers and booleans presumably do not have the allocation issue.
Exactly. The string returned from lua_tostring is only valid whilst there is a corresponding Lua string on the stack. So lua_tostring must put a Lua string somewhere on the stack. And the current implementation overwrites the number with the string.
I'm sure lots of people have been bitten by this behaviour (I know I have). Maybe it would be better if lua_tostring took an additional argument which was the stack slot to overwrite with the Lua string. Then it would be more clear that lua_tostring was doing something a bit different, and if you didn't want to change your number into a string you could do that by specifying a different stack slot. There are other variations that come to mind too.
drj