[ZScript] Parse INI-style data in lumps
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.
Got a cool project idea but nothing else? Put it in the project ideas thread instead!
Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.
Please read the full rules for more details.
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.
Got a cool project idea but nothing else? Put it in the project ideas thread instead!
Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.
Please read the full rules for more details.
-
- Posts: 184
- Joined: Tue Aug 30, 2016 4:47 pm
[ZScript] Parse INI-style data in lumps
I've written a library for parsing INI-style files from ZScript. See it on GitHub.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] Parse INI-style data in lumps
Sick!!! Thanks for putting this out. I'll most definitely have a use for this (with credits to you, of course).
-
- Posts: 184
- Joined: Tue Aug 30, 2016 4:47 pm
Re: [ZScript] Parse INI-style data in lumps
I've added several more features! Check out the updated README.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] Parse INI-style data in lumps
Thanks so much argv. Just curious, would it be hard to write a JSON or XML parser too?
-
- Posts: 184
- Joined: Tue Aug 30, 2016 4:47 pm
Re: [ZScript] Parse INI-style data in lumps
Impossible to do correctly, actually. ZScript cannot (as far as I know) decode UTF-8, which all JSON and most XML is encoded in.
Even with that, though, it would be very hard. Parsers in ZScript have to be written entirely by hand, since there are no parser generator tools or libraries for it (and they'd probably be agonizingly slow anyway). INI is a pretty trivial format, and it takes a fair bit of ZScript code to parse even that.
GZDoom actually comes with a JSON parser, which it uses for saved games. GZDoom save files are zips containing JSON files. It's not exposed to ZScript, though. If you want that, you could ask Graf to expose it.
Even with that, though, it would be very hard. Parsers in ZScript have to be written entirely by hand, since there are no parser generator tools or libraries for it (and they'd probably be agonizingly slow anyway). INI is a pretty trivial format, and it takes a fair bit of ZScript code to parse even that.
GZDoom actually comes with a JSON parser, which it uses for saved games. GZDoom save files are zips containing JSON files. It's not exposed to ZScript, though. If you want that, you could ask Graf to expose it.
-
- Posts: 1528
- Joined: Thu Jul 14, 2011 12:06 am
- Location: Gold Coast, Queensland, Australia
Re: [ZScript] Parse INI-style data in lumps
I have a number of classes and functions I've written that you may find useful for this, if you're interested in tackling it. Namely, I have Stream classes that support UTF-8, a hash map, a tokenizer, a StringUtility class that can handle Unicode and convert it to UTF-8, etc.argv wrote:Impossible to do correctly, actually. ZScript cannot (as far as I know) decode UTF-8, which all JSON and most XML is encoded in.
Even with that, though, it would be very hard. Parsers in ZScript have to be written entirely by hand, since there are no parser generator tools or libraries for it (and they'd probably be agonizingly slow anyway). INI is a pretty trivial format, and it takes a fair bit of ZScript code to parse even that.
GZDoom actually comes with a JSON parser, which it uses for saved games. GZDoom save files are zips containing JSON files. It's not exposed to ZScript, though. If you want that, you could ask Graf to expose it.
You can find it here: https://gitlab.com/TheZombieKiller/zk/t ... er/zk-core
I definitely agree that getting the JSON parser already present in the engine exposed to ZScript is the superior solution, though.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] Parse INI-style data in lumps
2 recent commits (this and this) is causing VM aborts (array out of bounds) with this library.
In particular, MergeByActorClass(); setting either purgeSuperSubSections or purgeNoMatch to true will cause the array out of bounds abort.
I'm too tired to look into this in more detail, I'm just putting this here so I can come back to this eventually
In particular, MergeByActorClass(); setting either purgeSuperSubSections or purgeNoMatch to true will cause the array out of bounds abort.
I'm too tired to look into this in more detail, I'm just putting this here so I can come back to this eventually
-
- Site Admin
- Posts: 7749
- Joined: Wed Jul 09, 2003 10:30 pm
Re: [ZScript] Parse INI-style data in lumps
Problem is this:
An unsigned integer can never be less than 0. sectionIndex was effectively a signed int before; now it gets to stay as unsigned. One fix would be to rewrite it so that you test with the pre-decremented value:
or declare sectionIndex as int instead.
Also, the second commit you linked is for making unsigned immediate values work. These are numbers that end with a u, like 0u, 32u, etc. So not applicable here.
Code: Select all
for (uint sectionIndex = Sections.Size() - 1; sectionIndex >= 0; sectionIndex--)
Code: Select all
for (uint sectionIndex = Sections.Size(); sectionIndex-- > 0; )
Also, the second commit you linked is for making unsigned immediate values work. These are numbers that end with a u, like 0u, 32u, etc. So not applicable here.
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZScript] Parse INI-style data in lumps
In cases like this I'd normally say "fix the mod", but if this had been used in released content that might be a problem.
If it can be version tested in the compiler it should be.
If it can be version tested in the compiler it should be.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] Parse INI-style data in lumps
Ah, woops, my bad, apologies - as I said, was tired when I made the post, I didn't look properlyrandi wrote: Also, the second commit you linked is for making unsigned immediate values work. These are numbers that end with a u, like 0u, 32u, etc. So not applicable here.
As far as this library goes - its advocated usage was "embed it into your mods" so who knows how many mods have embedded this library directly.
I can fix my local copy, of course, but I can't say the same for others...
-
- Posts: 537
- Joined: Wed Dec 22, 2021 7:02 pm
- Graphics Processor: Intel (Modern GZDoom)
- Location: Medellin, Colombia
Re: [ZScript] Parse INI-style data in lumps
FYI, regarding XML, I haven't tried it, but I saw this thread
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] Parse INI-style data in lumps
With the version set to 4.11.1 - there are now warnings about multi-returns: "Got 1, but expected 3" -- and furthermore, upgrading to 4.12 simply aborts startup with error.
Sample:
Sample:
Code: Select all
String, DisdainINISection, uint Get(String sectionName, String key, String default = "") const {
let section = Section(sectionName);
if (!section)
return default, null, 0;
String value;
uint keyIndex;
[value, keyIndex] = section.Get(key);
return value, section, keyIndex;
}
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] Parse INI-style data in lumps
I have found myself in a situation where I need to use this library again, but targeting the latest version of GZDoom at the time of this writing (which is GZDoom 4.13.2).
GZDoom 4.11.1 introduced some necessary API breakage that caused INIFile to no longer be usable. I also went ahead and fixed some deprecated code.
I've sent a fix pull request to argv's Github, but I'm unsure of their current status, as the repo hasn't been updated in 6 years, and argv's forum profile seems to have been purged. No idea if they're even still reading this.
In any case, I've attached the fixed package here.
GZDoom 4.11.1 introduced some necessary API breakage that caused INIFile to no longer be usable. I also went ahead and fixed some deprecated code.
I've sent a fix pull request to argv's Github, but I'm unsure of their current status, as the repo hasn't been updated in 6 years, and argv's forum profile seems to have been purged. No idea if they're even still reading this.
In any case, I've attached the fixed package here.
You do not have the required permissions to view the files attached to this post.