appendfile
Appends data to the end of a file, creating it if absent.
function appendfile(path: string, data: string): ()Synopsis
How it works
Appends data to the end of an existing file without overwriting its contents. Uses
CreateFileA with OPEN_ALWAYS disposition and seeks to end:
CreateFileA(path, FILE_APPEND_DATA, FILE_SHARE_READ,
NULL, OPEN_ALWAYS, 0, NULL);
// OPEN_ALWAYS: open if exists, create if not
SetFilePointer(handle, 0, NULL, FILE_END);
WriteFile(handle, data, dataLen, &bytesWritten, NULL);
CloseHandle(handle);
Creates the file if it doesn’t exist. The FILE_APPEND_DATA access right ensures the write always goes to the end, even if another process is writing concurrently. Ideal for log files.Usage
Append to a log
appendfile("log.txt", os.date() .. " ">-- joined game\n")Parameters
path string Path to the file.
data string The content to append.