lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Mar 11, 2009 at 06:44:53PM -0300, Guilherme wrote:
<snip>
>     luaL_loadfile( m_hPrivateState, "teste.lua" );

You need to lua_pcall the chunk returned by luaL_loadfile here.

As the reference manual says "Also as lua_load, this function only loads
the chunk; it does not run it."

As loading a chunk doesn't run it none of the function definitions in the
chunk will take effect until after you call it. Once you use lua_call or
lua_pcall on the loaded chunk you should be able to continue with the rest
of your example code.

> 	/* the function name */
> 	lua_getglobal(m_hPrivateState, "fadd");
>
> 	/* the first argument */
> 	lua_pushnumber(m_hPrivateState, x);
>
> 	/* the second argument */
> 	lua_pushnumber(m_hPrivateState, y);
>
> 	/* call the function with 2
> 	   arguments, return 1 result */
> 	lua_call( m_hPrivateState, 2, 1);

You may want to consider using lua_pcall instead of lua_call as it is used
to catch errors of this sort without crashing the host application.

<snip>

    -Etan