Lua:createTableFile

From Cheat Engine
Revision as of 19:05, 25 June 2026 by Leunsel (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<> Lua API Reference

function createTableFile(fileName, filePath OPTIONAL) : TableFile

Creates a new TableFile object and adds it to the current cheat table.

If filePath is specified, Cheat Engine reads the file from disk and embeds its contents in the table. If filePath is omitted, an empty table file is created.

Function Parameters[edit]

Parameter Type Description
fileName String The name the file will have inside the cheat table.
filePath String OPTIONAL The path to the file on disk. If omitted, a blank table file is created.

Returns[edit]

TableFile — The created table file object.

Description[edit]

createTableFile adds a file entry to the current cheat table.

This is useful for packaging resources with a table, such as sounds, images, binary data, configuration files, or other files used by Lua scripts. The file can later be retrieved with findTableFile, saved back to disk, or accessed through its MemoryStream.

Examples[edit]

Create a blank table file[edit]

1 local file = createTableFile("runtime.dat")
2 
3 print("Created table file: " .. file.Name)

Create a table file from disk[edit]

1 local file = createTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]])
2 
3 print("Added table file: " .. file.Name)

Play an embedded sound[edit]

1 local file = createTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]])
2 
3 playSound(file)

Create the file only if it does not already exist[edit]

1 local file = findTableFile("config.json")
2 
3 if file == nil then
4   file = createTableFile("config.json", [[C:\\SomeDirectory\\config.json]])
5 end
6 
7 print("Using table file: " .. file.Name)

Replace an existing table file[edit]

1 local oldFile = findTableFile("config.json")
2 
3 if oldFile ~= nil then
4   oldFile.delete()
5 end
6 
7 local newFile = createTableFile("config.json", [[C:\\SomeDirectory\\config.json]])
8 
9 print("Replaced table file: " .. newFile.Name)

Save the created table file to disk[edit]

1 local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]])
2 
3 file.saveToFile([[C:\\Temp\\data_copy.bin]])

Read the created file as a MemoryStream[edit]

1 local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]])
2 local stream = file.getData()
3 
4 print("Stream size: " .. tostring(stream.Size))

Access the Stream property[edit]

1 local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]])
2 local stream = file.Stream
3 
4 stream.Position = 0
5 
6 print("Stream size: " .. tostring(stream.Size))

Create multiple table files[edit]

 1 local files = {
 2   { name = "startup.wav", path = [[C:\\Sounds\\startup.wav]] },
 3   { name = "success.wav", path = [[C:\\Sounds\\success.wav]] },
 4   { name = "failed.wav",  path = [[C:\\Sounds\\failed.wav]] }
 5 }
 6 
 7 for i, entry in ipairs(files) do
 8   if findTableFile(entry.name) == nil then
 9     createTableFile(entry.name, entry.path)
10   end
11 end

Use a helper function[edit]

 1 local function ensureTableFile(name, path)
 2   local file = findTableFile(name)
 3 
 4   if file == nil then
 5     file = createTableFile(name, path)
 6   end
 7 
 8   return file
 9 end
10 
11 local sound = ensureTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]])
12 
13 playSound(sound)

Adding a File through the GUI[edit]

To add a file to your table manually, open the Table menu and choose Add File.

AddFile.png

Select the file you want to embed. Cheat Engine adds it to the table using the original filename.

After the file has been added, it appears as a separate entry below Add file in the Table menu. From there, you can rename it, save it to disk, or delete it.

AddedFileMenu.png

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Cheat Table Related Functions