lua-users home
lua-l archive

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

Is this lua_settop(L, 0) or any other remove, ... not needed?

static int Lcm_smw16(lua_State *L)
  Lcm* ud = (Lcm*)luaL_checkudata(L, 1, "Lcm");
  int a = luaL_checkint(L, 2);
  int d = luaL_checkint(L, 3);
  int blind = luaL_optint(L, 4, 0);
  lua_settop(L, 0); // <=== no need for this stack adjustment ?
  lua_pushnumber(L, ud->smw16(a, d, blind));
  return 1;

Mit freundlichen Grüßen / Best regards

Ruediger Dehmel

Von:        Dirk Laurie <>
An:        Lua mailing list <>,
Datum:        03/03/2014 10:18
Betreff:        Re: More lua stack operations support?
Gesendet von:

2014-03-03 10:50 GMT+02:00 Jean-Luc Jumpertz <>:

> In effect, it corresponds to a real and rather common use case where:
> - you want to push several "result" values to the stack,
> - for this you need to compute a number of intermediate stuff like table references and so push these intermediate values in the stack
> - you compute your "result" values that are located at the top of the stack
> - you need to remove the intermediate values from the stack in order to leave it in a clean non-leaking state

If you are returning to Lua, the return values are used and the stack
is cleaned up.
So this situation only applies when you staying in C.

I find it hard to imagine a situation where stack leakage would be
critical when you
have all the resources of C at your disposal.

Maybe you would be able to convince me if you showed an actual
rather than a hypothetical example.


atg Luther & Maelzer GmbH
Sitz / Company Seat : 97877 Wertheim / Germany
Strasse / Street : Zum Schlag 3
Amtsgericht / Local Court : Mannheim HRB 705702
Geschaeftsfuehrer / Managing Director : David G. Tacelli
USt.-Id. Nr. / VAT ID No. : DE 814 906 312
St.-Nr. / TIN No. : 80088 / 23872
Finanzamt / Revenue Office : Tauberbischofsheim

Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese E-Mail.
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail
ist nicht gestattet.
This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail.
Any unauthorised copying, disclosure or distribution of the material
in this e-mail is strictly forbidden.