Platform-native JSON parse/encode

Post Reply
Kovus
Inserter
Inserter
Posts: 23
Joined: Sat Feb 27, 2016 5:25 pm
Contact:

Platform-native JSON parse/encode

Post by Kovus »

It would be advantageous to me if there were a higher-performance interface for interacting with JSON data in Factorio.

Right now I'm using dkjson http://dkolf.de/src/dkjson-lua.fsl to do LUA table -> JSON encoding & parsing from JSON -> LUA table.

I'd read a benchmark of performance for that json module (and others) on time to do encode/decode of data, and the natively compiled (or LibPEG-enabled) libraries boasted results 2-20x better than what I can get by using a pure-lua implementation.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Platform-native JSON parse/encode

Post by eradicator »

May i ask what you're doing with json so frequenty that it affects performance?
(Also this should be in modding interface requests and not in suggestions...)

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Platform-native JSON parse/encode

Post by Rseding91 »

Why would you ever want to JSON encode/decode inside a mod which is 100% lua?
If you want to get ahold of me I'm almost always on Discord.

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Platform-native JSON parse/encode

Post by betrok »

Rseding91 wrote:Why would you ever want to JSON encode/decode inside a mod which is 100% lua?
Because it is more or less standard format for rpc? Although for factorio it's probably better to pass the lua table and eval it.

Kovus
Inserter
Inserter
Posts: 23
Joined: Sat Feb 27, 2016 5:25 pm
Contact:

Re: Platform-native JSON parse/encode

Post by Kovus »

I don't know that it is affecting performance, but with the potential performance difference between a pure-lua solution, and one that can take advantage of native code (including even libpeg), it seems reasonable to ask for it.

As to what I'm doing with it, I'm using json-encoded content as a way to pass data into/out of factorio games via rcon.

I tried passing lua tables via serpent.line/block, but it was entirely too painful to parse lua tables into something usable in another language, not to mention encoding them back into lua tables.

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Platform-native JSON parse/encode

Post by Bilka »

0.17 changelog wrote:Added LuaGameScript::table_to_json() and LuaGameScript::json_to_table().
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

JasonMiles
Burner Inserter
Burner Inserter
Posts: 15
Joined: Thu Sep 21, 2017 9:28 am
Contact:

Re: Platform-native JSON parse/encode

Post by JasonMiles »

Bilka wrote:
Fri Jun 22, 2018 1:48 pm
0.17 changelog wrote:Added LuaGameScript::table_to_json() and LuaGameScript::json_to_table().
Awesome, thank you :)

Would it be possible to also expose the base64 encoder/decoder in a similar way?
This would make exchanging mod state extremely easy (blueprint like).

Thanks!

Post Reply

Return to “Implemented mod requests”