Page 1 of 1
Platform-native JSON parse/encode
Posted: Fri Apr 27, 2018 9:27 pm
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.
Re: Platform-native JSON parse/encode
Posted: Sat Apr 28, 2018 3:21 am
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...)
Re: Platform-native JSON parse/encode
Posted: Tue May 01, 2018 7:22 am
by Rseding91
Why would you ever want to JSON encode/decode inside a mod which is 100% lua?
Re: Platform-native JSON parse/encode
Posted: Tue May 01, 2018 9:19 am
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.
Re: Platform-native JSON parse/encode
Posted: Tue May 15, 2018 1:57 am
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.
Re: Platform-native JSON parse/encode
Posted: Fri Jun 22, 2018 1:48 pm
by Bilka
0.17 changelog wrote:Added LuaGameScript::table_to_json() and LuaGameScript::json_to_table().
Re: Platform-native JSON parse/encode
Posted: Sun Oct 21, 2018 8:06 pm
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!