lua-users home
lua-l archive

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


> Subject: Lua and C++: Calling a Lua function in a script from C++
>
> How is this done?
>
> Ive read and read and didn't see anything that really covers this.

functions in lua are just values. global functions are global values, that
you can get and call like this: (code for Lua 4.0.1)

lua_getglobal(pLuaState, sFunction);
if(lua_isfunction(pLuaState, -1))
{
   int num_params = 0;
   // push Params here, if num_params != 0
   lua_call(pLuaState, num_params, 0)
}
else
   errormsg("The value is nil or another non-function value!!");

also see the chapter "Calling Lua Functions" from the reference manual.

hope this helps.

Cheers,
Peter