[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: FW: lua_isnumber modifying variables
- From: Mike Elson <Mike.Elson@...>
- Date: Fri, 22 Nov 2002 13:06:51 -0000
I'm using lua 4.01, and trying to pass string of numerical digits from a lua
script to a C++ application, _without_ converting it to a number on route.
Heres some code that illustrates the problem:
int main(void)
{
lua_State* state = lua_open(0);
lua_dostring(state,
"one=\"1111111011111111000111110000000000000000111111001111111100111111\"");
lua_getglobal(state, "one");
cout << "Isnumber returns " << lua_isnumber(state, -1) << endl;
cout << "Isstring returns " << lua_isstring(state, -1) << endl;
cout << "Read 'one', it is '" << lua_tostring(state, -1) << "'\n";
lua_close(state);
return 0;
}
and the result:
Isnumber returns 1
Isstring returns 1
Read 'one', it is '1.111111011111111e+63'
It has changed the string "one" into a floating point number.
If I remove the call to "lua_isnumber" the result is:
Isstring returns 1
Read 'one', it is
'1111111011111111000111110000000000000000111111001111111100111111'
Which is the result I'm after.
I can work around this by calling lua_type instead of lua_isnumber, but it
doesn't seem right that lua_isnumber should modify the variable it is
testing - is this behaviour correct?
Mike.