[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Environment of a Lua function called from C
- From: "Evan DeMond" <evan.demond@...>
- Date: Wed, 15 Aug 2007 00:10:23 -0500
What is the environment of a Lua function when called from C via lua_call or lua_pcall? I'm writing a C++ app that occasionally calls functions on the Lua side, and I hit a wall when I realized that these functions don't seem to have any of the standard Lua functions defined in their environments. The global environment seems to be missing. Nothing in my code calls setfenv or lua_setfenv.
Example from my code:
The calling C++ snippet:
// ... two arguments pushed here...
int status = lua_pcall(_lua, 2, 0, 0);
The Lua function (which trips up when called from C, because "pairs" turns out to be nil):
_OnNewMessage_ = function(someargs, moreargs)
for key, val in pairs(myapp.sometable) do
-> config/environment.lua:18: attempt to call global 'pairs' (a nil value)
Can the environment be clobbered as a side-effect of improper stack management, or anything like that? If anyone can shed some light, I'd be much obliged. Haven't found anything in the manual addressing this issue.