lua-users home
lua-l archive

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


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));