/*
* Calls the object as a function with the provided arguments,
* returning the function's returned values inside an array
*/
internal object[] callFunction(object function, object[] args)
{
int nArgs = 0;
int oldTop = LuaDLL.lua_gettop(luaState);
if (args != null && !LuaDLL.lua_checkstack(luaState, args.Length + 6))
{
throw new LuaException("Lua stack overflow");
}
translator.push(luaState, function);
if (args != null)
{
nArgs = args.Length;
for (int i = 0; i < args.Length; i++)
{
translator.push(luaState, args[i]);
}
}
int error = LuaDLL.lua_pcall(luaState, nArgs, -1, 0);
if (error != 0)
{
ThrowExceptionFromError(oldTop);
}
// object[] results = translator.popValues(luaState, oldTop);
// if (results != null && results.Length < 1)
// {
// return null;
// }
// return results;
return(translator.popValues(luaState, oldTop));
}