tw.file
Side: Shared
File loading and reading utilities for Lua modules and resource files.
Functions
tw.file.load(module_path) -> any
Loads and executes a Lua file, returning its result. Supports dot notation for paths and the @ prefix to load from other resources.
| Parameter | Type | Description |
|---|---|---|
module_path | string | Path in dot notation (e.g. "modules.utils" or "@other_resource.shared.helpers") |
Returns: any — The return value of the loaded Lua file.
lua
-- Load a file from the current resource
local utils = tw.file.load("modules.utils")
-- Load from another resource using @ prefix
local data = tw.file.load("@twinded_libs.locales.en")tw.file.read(...) -> content, resource_name, file_path
Reads the raw content of a file.
Returns:
| Return | Type | Description |
|---|---|---|
content | string | File content |
resource_name | string | Resource the file belongs to |
file_path | string | Resolved file path |
lua
local content, resource, path = tw.file.read("config.settings")
print(content)tw.file.exists(...) -> boolean
Checks if a file exists.
Returns: boolean — true if the file exists.
lua
if tw.file.exists("locales.fr") then
local fr = tw.file.load("locales.fr")
endExamples
Conditional locale loading
lua
local locale = tw.i18n.getLocale()
local path = "locales." .. locale
if tw.file.exists(path) then
local translations = tw.file.load(path)
tw.i18n.addEntries(translations)
endLoad a module from another resource
lua
local shared_data = tw.file.load("@twinded_libs.data.weapons")Notes
- Paths use dot notation, not slashes.
"modules.utils"resolves tomodules/utils.lua. - The
@prefix references another resource (e.g."@twinded_libs.shared"loads from thetwinded_libsresource). tw.file.loadexecutes the file and returns its result. Usetw.file.readif you only need the raw content.

