[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Determine if function is defined with C API?
- From: Joey Mukherjee <joey@...>
- Date: Fri, 1 Aug 2008 10:48:36 -0500
On Jul 31, 2008, at 10:12 PM, Patrick J. O'Leary Jr. wrote:
Ben Kelly wrote:
How would I do something like this? From lua_pcall, I get a
return
value of 2 but is this defined somewhere? Should I just check for
that value or is there a preferred constant?
This requires the function be on the stack and that you know the
index, though.
If he's in a position to use pcall on it, it's already on stack and
thus using lua_isfunction() is entirely reasonable, no?
Ben
I took the "return value of 2" to mean lua_pcall returned 2 (which
I believe
is LUA_ERRRUN) so perhaps the function is not on the stack? Simply
pushing
some random things onto the stack (none of which are functions) and
then
calling lua_pcall will give you a return value of 2. It could be the
function is on the stack but the number of arguments (nargs)
supplied to
lua_pcall is incorrect. I think further details from Joey are needed.
I think what I am doing is pushing random things on the stack and
hoping they exist. If they don't, I want to use my default routine.
If it does exist, and has an error, I want to inform the user. If
the function doesn't exist, I don't want the user to know or care.
Here's a snippet of my code:
lua_getglobal (LState,
"get_number_of_sensors"); // function to be called
if (lua_isfunction (LState, 0) == 1) {
if (lua_pcall (LState, 0, 1, 0) == 0) {
This doesn't work. Is it because I don't have the right index? I am
assuming the lua_getglobal either found the function or if it didn't,
how would I know? How do I find the right index to send to
lua_isfunction?
I feel like I am close, just missing some fundamental piece of
info! :-)
Thanks again,
Joey