[solved] data.write_file() - serpent to disk within data.lua

Things that already exist in the current mod API
Post Reply
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

[solved] data.write_file() - serpent to disk within data.lua

Post by aubergine18 »

Is it possible to get a .write_file() that's accessible from data.lua and data-final-fixes.lua?

Sometimes I make stupid mistake in my prototypes and it takes ages to try and work out where I've gone wrong because I can't serpent objects to file.

The only write_file() I'm aware of is part of the _G.game object, which isn't available from data.lua or data-final-fixes.lua scope.

If not available, serpent would also be a useful addition to the _G that's present during data.lua and data-final-fixes.lua.
Last edited by aubergine18 on Tue Sep 20, 2016 11:49 pm, edited 1 time in total.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: data.write_file() - for serpent to disk within data.lua

Post by prg »

serpent is already available during the data loading phase. You can use print() or log() to get at its output.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: data.write_file() - for serpent to disk within data.lua

Post by aubergine18 »

Do you have an example? I couldn't find the info about print() (other than game.player.print() which isn't avail in data load stage) or log() in the API docs..
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: data.write_file() - for serpent to disk within data.lua

Post by prg »

print() simply writes to stdout, where you can watch the output in a terminal or redirect it to a file manually.
log() produces an entry in the log file, like "0.320 Script data.lua:7: bla".
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: data.write_file() - for serpent to disk within data.lua

Post by aubergine18 »

I'm a bit useless when it comes to command line stuff so looks like log() is the right approach for me :) Thanks for the infos!
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: data.write_file() - for serpent to disk within data.lua

Post by aubergine18 »

Using serpent to dump data.raw to log:

Code: Select all

log( serpent.block( data.raw, {comment = false, numformat = '%1.8g' } ) )
Result: https://raw.githubusercontent.com/auber ... r/data.raw
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Post Reply

Return to “Already exists”