
Accessing a Lua Function from within C++
Using a similar process to that used in the last two sections, you can allow
your C/C++ program to access Lua functions. Let’s use the simple function
add as an example:
--function to add two numbers together and return the result
function add(a, b)
return (a + b)
end;
A Lua function is a type just like a number, string,ortable, so the process
for accessing one is familiar. First, place the function on the stack and
make sure what’s there is what you are expecting.
//get the function from the global table and push it on the stack
lua_getglobal(pL, "add");
//check that it is there
if (!lua_isfunction(pL, -1))
{
cout