Am 10.08.25 um 15:11 schrieb Hans Hagen via ntg-context:
On 8/10/2025 12:01 PM, Hraban Ramm wrote:

Am 10.08.25 um 11:41 schrieb Wolfgang Schuster:
Am 10.08.2025 um 11:33 schrieb Hraban Ramm:
for caching some generated data, I’d like to save a nested Lua table to a file, and load it later.
I found http://lua-users.org/wiki/SaveTableToFile
Is there already something (better) in ConTeXt? I'd assume, since the functionality is needed for tuc files?
table.tofile("my_file.lua",my_table)
Thank you, I overlooked that in cld-mkiv, since I was looking for table.save (which was mentioned in a thread about Ecir Baff’s art). And for reading context.runfile, right? What does it better than Lua’s dofile?
You don't tell what you want to do with the file
Load and process the table as if it was created directly.
table.save("my_file.lua",my_table)
What’s the difference between table.tofile and table.save? tofile is documented in cld-mkiv* while save is not. table.save is also not mentioned in the Lua reference manual. Where does it come from?
my_table = tabel.load("my_file.lua")

wrt runfiles benefits:
- finding the file
- checking it
- reporting on it

Great, thank you!

*) BTW, cld-mkiv speaks of "luafilesystem" while the library is called "lfs".

(It’s strange, while in Python I just try everything, in Lua I feel the need to check every step… Maybe it’s because I want my code to be "best practice" because it might become part of documentation… And of course I still lack the same experience that I have in Python.)

Hraban

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to