コード例 #1
0
        private int removeelements(IntPtr L)
        {
            if (!IsXmlFileLoaded())
            {
                return(Melua.melua_error(L, "No XML file loaded."));
            }

            var selectors = new HashSet <string>();

            if (Melua.lua_isstring(L, -1))
            {
                var selector = Melua.luaL_checkstring(L, 1);
                Melua.lua_pop(L, 1);

                if (!IsXPathValid(selector))
                {
                    return(Melua.melua_error(L, "Invalid XPath."));
                }

                selectors.Add(selector);
            }
            else if (Melua.lua_istable(L, -1))
            {
                Melua.lua_pushnil(L);
                while (Melua.lua_next(L, -2) != 0)
                {
                    var selector = Melua.luaL_checkstring(L, -1);
                    Melua.lua_pop(L, 1);

                    if (!IsXPathValid(selector))
                    {
                        return(Melua.melua_error(L, "Invalid XPath."));
                    }

                    selectors.Add(selector);
                }
            }
            else
            {
                return(Melua.melua_error(L, "Invalid argument type '{0}'.", Melua.luaL_typename(L, -1)));
            }

            var modder = _loadedXmlModder;

            foreach (var selector in selectors)
            {
                _modPack.AddMod(new XmlElementRemover(modder, selector));
            }

            return(0);
        }
コード例 #2
0
        private int setattributes(IntPtr L)
        {
            if (!IsXmlFileLoaded())
            {
                return(Melua.melua_error(L, "No XML file loaded."));
            }

            var modder = _loadedXmlModder;

            var selector = Melua.luaL_checkstring(L, 1);

            if (!IsXPathValid(selector))
            {
                return(Melua.melua_error(L, "Invalid XPath."));
            }

            if (Melua.lua_isstring(L, 2) && Melua.lua_isstring(L, 3))
            {
                var attributeName  = Melua.lua_tostring(L, 2);
                var attributeValue = Melua.lua_tostring(L, 3);
                Melua.lua_pop(L, 2);

                _modPack.AddMod(new XmlAttributeSetter(modder, selector, attributeName, attributeValue));
            }
            else if (Melua.lua_istable(L, 2))
            {
                Melua.lua_pushnil(L);
                while (Melua.lua_next(L, -2) != 0)
                {
                    var attributeName  = Melua.luaL_checkstring(L, -2);
                    var attributeValue = Melua.luaL_checkstring(L, -1);
                    Melua.lua_pop(L, 1);

                    _modPack.AddMod(new XmlAttributeSetter(modder, selector, attributeName, attributeValue));
                }

                Melua.lua_pop(L, 1);
            }
            else
            {
                return(Melua.melua_error(L, "Invalid argument type."));
            }

            Melua.lua_pop(L, 1);

            return(0);
        }