Problems migrating lua_cpcall to version 5.3

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems migrating lua_cpcall to version 5.3

Mike Maikaefer
Hi,

I have some code which makes use of the deprecated function lua_cpcall:

   s.argv[0]=NULL;
   s.argv[1]=data->config.m_luafile;
   s.argv[2]=NULL;
   status = lua_cpcall(L, &pmain, &s);
   report(L, status);

Now the manual says i have to replace lua_cpcall by lua_pushfunction and lua_pcall. What I don't understand: how can I hand over my arguments "s" with these new functions? They don't seem to have a possibility to deal with this kind of parameter which has to be forwarded to the called function "pmain"!

Thanks :-)


Reply | Threaded
Open this post in threaded view
|

Re: Problems migrating lua_cpcall to version 5.3

Roberto Ierusalimschy
> I have some code which makes use of the deprecated function lua_cpcall:
>
>    s.argv[0]=NULL;
>    s.argv[1]=data->config.m_luafile;
>    s.argv[2]=NULL;
>    status = lua_cpcall(L, &pmain, &s);
>    report(L, status);
>
> Now the manual says i have to replace lua_cpcall by lua_pushfunction and
> lua_pcall. What I don't understand: how can I hand over my arguments "s"
> with these new functions? They don't seem to have a possibility to deal
> with this kind of parameter which has to be forwarded to the called
> function "pmain"!

You pass it as a regular argument to your function:

  lua_pushcfunction(L, &pmain);
  lua_pushlightuserdata(L, &s);
  status = lua_pcall(L, 1, 0, 0);

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Problems migrating lua_cpcall to version 5.3

Mike Maikaefer
Great - thanks! :-)

On Tue, Apr 3, 2018 at 10:15 PM, Roberto Ierusalimschy <[hidden email]> wrote:
> I have some code which makes use of the deprecated function lua_cpcall:
>
>    s.argv[0]=NULL;
>    s.argv[1]=data->config.m_luafile;
>    s.argv[2]=NULL;
>    status = lua_cpcall(L, &pmain, &s);
>    report(L, status);
>
> Now the manual says i have to replace lua_cpcall by lua_pushfunction and
> lua_pcall. What I don't understand: how can I hand over my arguments "s"
> with these new functions? They don't seem to have a possibility to deal
> with this kind of parameter which has to be forwarded to the called
> function "pmain"!

You pass it as a regular argument to your function:

  lua_pushcfunction(L, &pmain);
  lua_pushlightuserdata(L, &s);
  status = lua_pcall(L, 1, 0, 0);

-- Roberto