[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Call a Lua function from C
- From: David Jones <drj@...>
- Date: Wed, 2 Feb 2005 17:51:27 +0000
On Feb 02, 2005, at 14:45, Michael Cumming wrote:
Thank you for the replys... so a quick guess at the code would be...
if (lua_isfunction (L,1)) // we have a function
luacallbackfunction = luaL_ref(L, LUA_REGISTRYINDEX);
When I want to use the function I can do
lua_rawgeti(L, LUA_REGISTRYINDEX, luacallbackfunction);
lua_pushxxx for the params
Looks about right.
By the way, since tables and userdata can also be called if they have
the correct metamethod then it is bad practice to use lua_isfunction to
test if a value is callable. I might, quite reasonably, pass in a
"function" that was in fact a userdata that implemented the __call
metamethod and your code would barf. On the other hand, I appreciate
that you would like _some_ sanity check.