Skip to content

Noita-compatible non-conformant XML parser written in Lua

Notifications You must be signed in to change notification settings

NathanSnail/luanxml

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 

Repository files navigation

This is a fork of LuaNXML with LuaCATS annotations and a few bugfixes.

LuaNXML

LuaNXML is a Lua port of NXML.

NXML is a pseudo-XML parser that can read and write the oddly formatted and often invalid XML files from Noita. NXML (the C#/.NET version linked before) is itself a port of the XML parser from Poro, which is used by the custom Falling Everything engine on which Noita runs.

In short, LuaNXML is an XML parser that is 100% equivalent to Noita's parser. As opposed to something like xml2lua, LuaNXML is just as non-conformant to the XML specification as Noita itself. It can also produce semantically equivalent output in the form of a string.

Example

The code below enables all mods in the mod_config.xml file by setting the enabled attribute on all children to true. Boolean values are automatically converted to Noita XML style "1" or "0" values when :set is used.

---@type nxml
local nxml = require("nxml")

---@param path string
---@return string
local function read(path)
	local f = io.open(path, "r")
	local content = f:read("*a")
	f:close()
	return content
end

---@param path string
---@param content string
local function write(path, content)
	local f = io.open(path, "w")
	f:write(content)
	f:close()
end

for content in nxml.edit_file("save00/mod_config.xml", read, write) do
	for elem in content:each_child() do
		elem:set("enabled", true)
	end
end

API

The api of NXML is entirely documented within the code via LuaCATS so your editor should provide autocomplete and type checking for all of NXMLs features.

About

Noita-compatible non-conformant XML parser written in Lua

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%