Sorry, we don't support your browser.  Install a modern browser
This post is closed.

pattern too complex#858

Trying to use string.match() in Lua I get a “pattern to complex” exception.
According to the documentation
http://www.lua.org/bugs.html[#5](/5).2.1-1
That is a bug solved in Lua 5.2.1

What version of Lua is used in TTS?
This is the function that causes issues.

pippo = string.match(stringa, ‘.*^{“object”:”list”,”total_cards”‘)

where “Stringa” is what is returned by this API call:

https://api.scryfall.com/cards/search?unique=prints&order=released&q=name%3ASettle%20the%20Wreckage&dir=asc

Thanks

3 years ago

This is a limitation of the lua interpreter, not the language, and TTS doesn’t use the lua interpreter at all. It uses MoonSharp.

/execute print(logString(_MOONSHARP)) outputs

  "version": 2.0.0.0
  "luacompat": 5.2
  "platform": limited.unity.dll.mono.clr4
  "is_aot": false
  "is_unity": true
  "is_mono": true
  "is_clr4": true
  "is_pcl": false
  "banner": MoonSharp 2.0.0.0 [​​​​​​​limited.unity.dll.mono.clr4]
Copyright (C) 2014-2016 Marco Mastropaolo
http://www.moonsharp.org

As you can see, it uses MoonSharp 2.0.0.0, which is the latest release of MoonSharp.

The output mentions compatibility with Lua 5.2, but that refers to version 5.2 of the language, not the interpreter. The presence or absence of the limitation is not related to this.

3 years ago
1

Note that .*^{"object":"list","total_cards" can never match a JSON document (such as what scryfall returns) anyway.

Maybe if you fix your own bug, this limitation will become moot. For starters, matching a regex pattern against JSON just isn’t right.

3 years ago
1

Thanks, yeah I noticed that but also by correcting the pattern I would still get that error.

What I’m after is getting only the first card returned. Parsing the output with JSON.decode() unfortunately for some reason takes a really long time and hangs the UI in the while. So I wanted to try the “manual” way but to no avail. Thanks for any hint you may be willing to share!

3 years ago

at the risk of getting into off topic computer science stuff, ikegami is right: regex isn’t the tool to use for parsing a nested structure like json. the typical way to parse strings like that is to write a tokenizer - it’s also how you parse out things like mathematical equations stored in strings in a safe way. Computerphile on youtube does a really good job of explaning some of the theory behind it (stacks and reverse polish notation, things like that). But ultimately, that’s how you do it.

But that being said. JSON.decode() will be easier and faster. The truth of the matter is that decoding json is a pretty expensive process to do.

3 years ago
Changed the status to
Archived
3 years ago