Ejemplo n.º 1
0
        // -------------------------------------------------------------------------------------------------------------
        // Public interfaces
        // -------------------------------------------------------------------------------------------------------------

        public object[] DoBuffer(byte[] chunk, string chunkName = "chunk")
        {
            int oldTop = LuaLib.lua_gettop(L);

            if (LuaLib.luaL_loadbuffer(L, chunk, chunk.Length, chunkName) != 0)                 // |f or |err
            {
                string error = LuaLib.lua_tostring(L, -1);                                      // |err
                LuaLib.lua_settop(L, oldTop);                                                   // |

                throw new LuaException(error);
            }
            if (LuaLib.lua_pcall(L, 0, LuaLib.LUA_MULTRET, 0) != 0)                                             // | or |ret1|ret2 or |err
            {
                string error = LuaLib.lua_tostring(L, -1);                                                      // |err
                LuaLib.lua_settop(L, oldTop);                                                                   // |

                throw new LuaException(error);
            }

            int top = LuaLib.lua_gettop(L);

            if (top == oldTop)
            {
                return(null);
            }

            var objects = new List <object>();

            for (int i = oldTop + 1; i <= top; ++i)
            {
                objects.Add(ToObject(i));
            }

            LuaLib.lua_pop(L, top - oldTop);

            return(objects.ToArray());
        }