Welcome to the PtokaX Wiki!
This wiki is devoted to let users share information on the great hubsoft PtokaX. However, it is not limited to PtokaX, it is destined to share and discuss information on different parts of the LUA programming language, but the site is NOT intended to be a replacement for the primary LUA Board aka the PtokaX Portal, nor the secondary LUA Board or the PtokaX resources.
If you’re not familiar with wikis then in short: they are user-contributed sites: pages can be edited by (almost) anyone. As such, there is always kind of up-to-date and (hopefully) proper content. They are better than forums, since relevant pieces of information are on the same page. Do not hesitate to share your knowledge, and we all hope you can learn and teach a lot here! — bastya_elvtars
Trace: » Tips on scripting in API v.2 » PtokaX Service Installation Guide » The Operating System Library in Lua 5.1.x » Overview of the PtokaX API2 » Using the string library in LUA » Metatables and metamethods » Setting up PtokaX » main » how_to_register » File manipulation
File manipulation
Introduction
Scripts often store metadata in files allowing them to recall it later. They are also capable of logging, etc. Files storing the information do not have to follow the LUA syntax, with proper pattern matching any type of information can be read from a properly saved file. In fact, serialization can be very heavy but sometimes (nested tables) that's the only way.
The following chapters will cover some aspects of file management, like file analyzing, storing and retrieving data, and some other operations.
Examples are from Lua 5 File Handling Guide / By NightLitch
Opening files
Way #1
--// Simple Reading File function ReadFile(filename) io.input(filename) -- The input for reading is a file. for line in io.lines() do -- We iterate through the lines of the input -- todo code here end io.input() -- Closing it... end
If you wanna iterate through a file and you are 1000% sure it exists, then no need to open/close it, io.lines(filename) runs through the lines, doing the open/close jobs as well.
Way #2
We create file handlers.
local f=io.open(file,"r,")
You are here: About the Wiki » scriptinghelp » File manipulation