# Problems with lua_call

## Recommended Posts

brain21    128
hi, I am using lua_call in my app and I can't seem to get it to work. It keeps quiting the program right after the call. I'm using references. I use a lua funtion to register a reference of a lua function into the host (c/C++), then later I use these lines to try to call that function.
[Lua Function]
function SomeFunction( n )
return n
end

[C Code]
lua_rawgeti( L, LUA_REGISTRYINDEX, ref );
lua_pushnumber( L, param1 );
lua_call( L, 1, 1 );


so, I know that ref is a number, but the call just exits the program. I try to use pcall with 0 as a last parameter and that doesn't exit the program, but does not run the function either. I'm so comfused. Can anyone help? I'm using Lua 5.0 with MSVC++ 6.0 Denny.

##### Share on other sites
Sneftel    1788
is lua_rawgeti successfully getting the value, or pushing nil? What error is thrown by lua_call?

##### Share on other sites
Guest Anonymous Poster
What does ref equal? Unless you are also registering your function in the registry independently, you need to retrieve it from LUA_GLOBALSINDEX not LUA_REGISTRYINDEX.

##### Share on other sites
brain21    128
After more debuging:
[EDIT]
ok here's what I;ve found out. if I call a Lua function from my C program and that function (Lua) calls a C function that is not registered, no errors will be generated. Strange. Has anyone experienced this?

[MORE EDITS]
I just found lua_pcall and am using the return of this to pring my errors.

Sorry for the topic, and tanks alot for your help.

denny.

[Edited by - brain21 on February 15, 2005 9:06:53 PM]