[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Function call with number parameter becomes a string parameter inside the function
- From: David Jones <drj@...>
- Date: Thu, 29 Jun 2006 11:46:42 +0100
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
lua_tostring() from my code.
However, I'm wondering why lua_tostring() behaves in this (somewhat
surprising) manner? This makes it different from all the other
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.