Sign in to follow this  

Problems with lua_call

Recommended Posts

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

[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 this post

Link to post
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 this post

Link to post
Share on other sites
After more debuging:
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?

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.


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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this