Thread: JSON to Lua
View Single Post
10/08/19, 04:54 AM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Don't think that's enough. You'd still need to serialize it into Lua code so the game can load it.

As I see it you have two different approaches you can take. Either you convert it before the game loads it, or after.

In the first case you have to use some library that can read the JSON data and another library to serialize it into Lua code that can be read by the game. Reading the JSON data is the smallest issue here as it is well supported in plenty of languages. The problem is how to generate the Lua code. There doesn't seem to be any out of the box solutions, but then again it's not really hard to do it yourself with a few lines of code. It won't even matter which language you use for that. JS, Lua, Java - anything is fine.
If you want to avoid that problem altogether you could look for a pure Lua implementation of a JSON library, write a small addon that takes JSON in a text field, put it into a saved variable and let the game serialize it for you.

The other way would be to simply dump the JSON string into a Lua string and then deserialize it at runtime with said pure Lua implementation of a JSON library. That may be a bit simpler in terms of complexity, but may cause performance issues depending on how much data you want to load that way.
  Reply With Quote