lua-users home
lua-l archive

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

Quoth Roberto Ierusalimschy <>, on 2010-03-29 11:22:58 -0300:
> In 5.2, luaL_cpcall is able to return values. Doesn't that solve
> the problem? (luaL_cpcall is also cheaper than 5.1's lua_cpcall.)

Just to be clear, in a sense it doesn't need to be "solved" because
it's already possible, just awkward, so I think the question is more
whether it makes the API nicer.

Anyway, I hadn't looked at the latest 5.2 when I wrote that.  If
luaL_cpcall acts like lua_cpcall but with return values, then it would
be marginally easier, but you'd still have that extra C function,
which is a large part of the pain of that solution.  I don't see
luaL_cpcall per se in the manual or source of 5.2-work2, though, so I
can't really tell the details; perhaps I'm missing something.

FWIW, here's how I'd add such convenience functions, if I were tasked
with adding them.  Name them with s/^lua_/luaL_p/ or thereabouts:

  luaL_ppushlstring, luaL_pcreatetable, luaL_ppushcclosure,
  luaL_pnewuserdata, luaL_pnewthread

The functions whose plain counterparts return pointers (pushlstring,
newuserdata, newthread) would return NULL on failure; the functions
whose plain counterparts return void (createtable, pushcclosure) would
return 1 on success or 0 on failure.  Failure would push nothing,
rather than nil; cf. lua_getmetatable for symmetry.

(I might try to draw up a patch if even for local use, now that I
think about it.  If so, I'll send it to the list.)

> -- Roberto

   ---> Drake Wilson