lua-users home
lua-l archive

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


On Sat, Aug 21, 2010 at 9:17 PM, Joachim Buermann <jbuermann@iftools.com> wrote:
>    if( luaL_loadstring( L, "result=counter()" ) != 0 ) {
>
>           std::cout << "Error" << std::endl;
>
>    }
>
>    lua_pcall( L, 0, 0, 0 );
>
>    lua_pcall( L, 0, 0, 0 );
>
>    lua_getglobal( L, "result" );

As well as running the compiled chunk, lua_pcall() removes it from the
stack, so the second call will not be trying to run the same compiled
chunk.

To counteract this, try making a copy of the compiled chunk value by
using lua_pushvalue(), so the copy is removed instead:

  lua_pushvalue(L, -1);
  lua_pcall(L, 0, 0, 0);
  lua_pushvalue(L, -1);
  lua_pcall(L, 0, 0, 0);

-Duncan