On Tue, Feb 26, 2013 at 9:14 PM, Thomas Harning Jr. <harningt@xxxxxxxxx> wrote: > On Tue, Feb 26, 2013 at 8:56 PM, Hadriel Kaplan <hadrielk@xxxxxxxxx> wrote: >> >> Sure, when called by Lua - but when bitop's embedded, and this func is >> called by other C-code to load it in some chain of loading libs, I would >> think the normal expectation is to get back the number of results pushed >> (ie, keep it balanced modulo the return value). >> >> As I said, not a big deal (it's "trivial") and your call... just noting it >> in case you didn't intend it. >> >> -hadriel >> p.s. thanks for bitop, BTW! > luaopen_* calls typically expect to be in an isolated environment, ex: > the standard Lua library registration expects to be called with their > own function environments. > > A way to call this properly in an embedded environment would be to do > the following: > > lua_push > Whoops, accidentally hit send too early. lua_pushcfunction(L, luaopen_bit); lua_pushstring(L, "bit"); /* Name of library base name - some modules expect this */ lua_call(L, 1, 1); /* 1 arg w/ 1 forced return value, w/ registrations that affect global environment you could use lua_call(L, 1, 0); to ignore return value */ -- Thomas Harning Jr. (http://about.me/harningt)