/// <summary>
/// Executes a Lua chnk and returns all the chunk's return values in an array.
/// </summary>
/// <param name="chunk">Chunk to execute</param>
/// <param name="chunkName">Name to associate with the chunk</param>
/// <returns></returns>
public object[] DoString(string chunk, string chunkName, LuaTable env)
{
int oldTop = LuaDLL.lua_gettop(L);
byte[] bt = Encoding.UTF8.GetBytes(chunk);
if (LuaDLL.luaL_loadbuffer(L, bt, bt.Length, chunkName) == 0)
{
if (env != null)
{
env.push(L);
//LuaDLL.lua_setfenv(L, -1);
LuaDLL.lua_setfenv(L, -2);
}
if (LuaDLL.lua_pcall(L, 0, -1, 0) == 0)
{
return(translator.popValues(L, oldTop));
}
else
{
ThrowExceptionFromError(oldTop);
}
}
else
{
ThrowExceptionFromError(oldTop);
}
return(null); // Never reached - keeps compiler happy
}