Exemple #1
0
        public void typename()
        {
            var L = Melua.luaL_newstate();

            Melua.lua_pushinteger(L, 123);
            Assert.Equal("number", Melua.luaL_typename(L, -1));

            Melua.lua_pushstring(L, "123");
            Assert.Equal("string", Melua.luaL_typename(L, -1));

            Melua.lua_newtable(L);
            Assert.Equal("table", Melua.luaL_typename(L, -1));
        }
Exemple #2
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);
        }