Ejemplo n.º 1
0
        /// <summary>
        /// [-(0|1), +0, v] Checks that the value on top of the stack is the given type. If it isn't then the value is popped, the instance is disposed, and an exception is thrown.
        /// Validating the type is critically important because some Lua functions don't check the type at all, potentially corrupting memory when given unexpected input.
        /// </summary>
        protected void CheckType(lua.State L, LUA.T t)
        {
            Debug.Assert(L == Owner._L);
            var actual = lua.type(L, -1);

            if (actual == t)
            {
                return;
            }
            lua.pop(L, 1);
            Dispose();
            throw NewBadTypeError(t, actual);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// [-0, +0, v] Checks that the instance references the given type. If it doesn't, the instance is disposed and an exception is thrown.
        /// Validating the type is critically important because some Lua functions don't check the type at all, potentially corrupting memory when given unexpected input.
        /// </summary>
        protected void CheckType(LUA.T t)
        {
            var L = Owner._L;

            luanet.checkstack(L, 1, "LuaBase.CheckType");
            luaL.getref(L, Reference);
            var actual = lua.type(L, -1);

            lua.pop(L, 1);
            if (actual != t)
            {
                Dispose();
                throw NewBadTypeError(t, actual);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// [-1, +0, v] Pops a value from the top of the stack and returns a reference or throws if it doesn't match the provided type.
        /// Validating the type is critically important because some Lua functions don't check the type at all, potentially corrupting memory when given unexpected input.
        /// </summary>
        protected static int TryRef(lua.State L, Lua interpreter, LUA.T t)
        {
            Debug.Assert(L == interpreter._L);
            var actual = lua.type(L, -1);

            if (actual == t)
            {
                return(luaL.@ref(L));
            }
            else
            {
                lua.pop(L, 1);
                throw NewBadTypeError(typeof(LuaBase).Name, t, actual);
            }
        }