[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bug using Lua 5.2.0 in VS2005
- From: HyperHacker <hyperhacker@...>
- Date: Tue, 7 Feb 2012 02:21:17 -0700
On Tue, Feb 7, 2012 at 02:19, Rebel Neurofog <rebelneurofog@gmail.com> wrote:
> On Tue, Feb 7, 2012 at 1:15 PM, John Tan <johnmave126@gmail.com> wrote:
>> The following codes could perform the bug
>> //C Source Code
>> #include "lua.hpp"
>> int f1(lua_State *L) {
>> printf("%d\n", lua_tonumber(L, 1));
>> return 0;
>> }
>> int main (int argc, char* argv[]) {
>> lua_State *L = luaL_newstate();
>> luaL_openlibs(L);
>> lua_pushcfunction(L, f1);
>> lua_setglobal(L, "f1");
>> lua_getglobal(L, "f1");
>> lua_pushnumber(L, 1);
>> lua_call(L, 1, 0);
>> return 0;
>> }
>>
>> After executing it,f1 will print 0 on the screen which indicates that it
>> gets nil on stack when it is called.
>> I don't know if there is anybody else meeting the same problem...
>> Hope to know what has happened...THX
>
> Try printf("%d\n", (int) lua_tonumber(L, 1));
>
Or better, use lua_tointeger() instead of lua_tonumber(), since the
latter returns a double.
--
Sent from my toaster.