Class: ini_file
LTX/INI file reader and writer.
Use it to read config sections and fields from game data, or to create small script-owned config files. Engine configs support section inheritance and #include statements.
Source
C++ class ini_file
Custom Constructor
ini_file
Remarks
Most typed read methods use the engine's strict config readers. Check section_exist and line_exist first when missing data is valid for your script.
Constructors
Constructor
new ini_file(): ini_file;Create an empty ini file.
Returns
ini_file
Constructor
new ini_file(path: string): ini_file;Open an ini file from the game config path.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File name or path relative to $game_config$. |
Returns
ini_file
Remarks
This constructor resolves path below $game_config$.
Constructor
new ini_file(initial: string, path: string): ini_file;Open an ini file from a filesystem alias and relative path.
Parameters
| Parameter | Type | Description |
|---|---|---|
initial | string | Filesystem alias, for example $game_config$. |
path | string | File name or path relative to the alias. |
Returns
ini_file
Methods
fname()
fname(): string;Get file name and path of ini file.
Returns
string
Full path to ini file.
Example
`f:\applications\steam\steamapps\common\stalker call of pripyat\gamedata\configs\misc\task_manager.ltx`line_count()
line_count(section: string): number;Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Target section to check lines count. |
Returns
number
Count of lines for provided section.
Remarks
Missing sections are an engine assertion path. The recoverable branch returns 0.
line_exist()
line_exist(section: Nillable<string>, field: string): boolean;Check if line exists in the file by section and field.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | Nillable<string> | Target section to check. |
field | string | Section field to check. |
Returns
boolean
Whether line exists.
r_bool()
r_bool(section: string, field: string): boolean;Read a boolean value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
Returns
boolean
Parsed boolean value.
r_clsid()
r_clsid(section: string, field: string): number;Read a class identifier value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
Returns
number
Parsed class identifier.
r_float()
r_float(section: string, field: string): number;Read a floating-point value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
Returns
number
Parsed number.
Throws
If the section or field does not exist.
r_line()
r_line<T, P>(
section: string,
line_number: number,
key: string,
value: string): LuaMultiReturn<[boolean, T, P]>;Read text line from ini config file.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends string | string |
P extends string | string |
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
line_number | number | Zero-based line index inside the section. |
key | string | Placeholder for Lua out parameter. |
value | string | Placeholder for Lua out parameter. |
Returns
LuaMultiReturn<[boolean, T, P]>
Success flag, key, and value.
Remarks
Returns false for an out-of-range line index. A missing section is a hard engine error.
Throws
If the section does not exist.
r_s32()
r_s32(section: string, field: string): number;Read a signed 32-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
Returns
number
Parsed integer.
Throws
If the section or field does not exist.
r_string()
r_string(section: string, field: string): string;Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Ini file section. |
field | string | Ini section field. |
Returns
string
Raw string from ltx file without spaces in it.
Throws
If the section or field does not exist.
r_string_wb()
r_string_wb(section: string, field: string): string;Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Ini file section. |
field | string | Ini section field. |
Returns
string
If quoted, parsed string data inside quotes including spaces, else is same data as with r_string.
Remarks
Reads a string with blanks preserved by the engine parser.
r_string_wq()
r_string_wq(section: string, field: string): string;Read a quoted string value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
Returns
string
Parsed string.
Remarks
Uses the same engine reader as r_string_wb; quoted values may keep spaces.
r_token()
r_token(
section: string,
field: string,
list: token_list): number;Read a token value using a token list.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
list | token_list | Token list used for lookup. |
Returns
number
Token id.
r_u32()
r_u32(section: string, field: string): number;Read an unsigned 32-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
Returns
number
Parsed integer.
Throws
If the section or field does not exist.
r_vector()
r_vector(section: string, field: string): vector;Read a 3D vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
Returns
Parsed vector.
Throws
If the section or field does not exist.
remove_line()
remove_line(section: string, field: string): void;Remove ini file section field.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Target section to modify. |
field | string | Target section field to remove. |
Returns
void
save_as()
save_as(path: string): boolean;Save this ini file to a path.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Destination path. |
Returns
boolean
Whether saving succeeded.
Throws
If path is missing.
save_at_end()
save_at_end(should_save: boolean): void;Adjust saving on file closing/destructor calls.
Parameters
| Parameter | Type | Description |
|---|---|---|
should_save | boolean | Whether ini file should be saved when destructor is called. |
Returns
void
Remarks
Intended for script-created or script-owned ini files. Be careful using it on engine-owned singletons returned by game_ini or system_ini.
section_count()
section_count(): number;Returns
number
Number of sections in this file.
section_exist()
section_exist(section: Nillable<string>): boolean;Check whether a section exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | Nillable<string> | Section name. |
Returns
boolean
Whether the section exists.
section_for_each()
section_for_each(cb: (this: void, name: string) => void): void;Iterate over ini file sections. Calls provided callback for each ini section in file.
Parameters
| Parameter | Type | Description |
|---|---|---|
cb | (this: void, name: string) => void | Callback to call on each ini file section, where name is section name. |
Returns
void
set_override_names()
set_override_names(override: boolean): void;Enable or disable section override name handling.
Parameters
| Parameter | Type | Description |
|---|---|---|
override | boolean | Whether override names should be used. |
Returns
void
Since
OpenXRay 2017-08-15, 565b39e5
set_readonly()
set_readonly(is_readonly: boolean): void;Switch the file into readonly or writable mode.
Parameters
| Parameter | Type | Description |
|---|---|---|
is_readonly | boolean | Whether writes should be disabled. |
Returns
void
w_bool()
w_bool(
section: string,
field: string,
value: boolean,
comment?: string): void;Write a boolean value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | boolean | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_color()
w_color(
section: string,
field: string,
color: number,
comment?: string): void;Write a packed color value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
color | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_fcolor()
w_fcolor(
section: string,
field: string,
color: fcolor,
comment?: string): void;Write a floating-point color value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
color | fcolor | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_float()
w_float(
section: string,
field: string,
value: number,
comment?: string): void;Write a floating-point number.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_fvector2()
w_fvector2(
section: string,
field: string,
vector: vector2,
comment?: string): void;Write a 2D vector value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
vector | vector2 | Value to write. |
comment? | string | Optional line comment. |
Returns
void
Since
OpenXRay 2017-08-15, 565b39e5
w_fvector3()
w_fvector3(
section: string,
field: string,
vector: vector,
comment?: string): void;Write a 3D vector value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
vector | vector | Value to write. |
comment? | string | Optional line comment. |
Returns
void
Since
OpenXRay 2017-08-15, 565b39e5
w_fvector4()
w_fvector4(
section: string,
field: string,
vector: never,
comment?: string): void;Write a 4D vector value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
vector | never | Value to write. |
comment? | string | Optional line comment. |
Returns
void
Since
OpenXRay 2017-08-15, 565b39e5
w_s16()
w_s16(
section: string,
field: string,
value: number,
comment?: string): void;Write a signed 16-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_s32()
w_s32(
section: string,
field: string,
value: number,
comment?: string): void;Write a signed 32-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_s64()
w_s64(
section: string,
field: string,
value: number,
comment?: string): void;Write a signed 64-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_s8()
w_s8(
section: string,
field: string,
value: number,
comment?: string): void;Write a signed 8-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_string()
w_string(
section: string,
field: string,
value: string,
comment?: string): void;Write a string value.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | string | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_u16()
w_u16(
section: string,
field: string,
value: number,
comment?: string): void;Write an unsigned 16-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_u32()
w_u32(
section: string,
field: string,
value: number,
comment?: string): void;Write an unsigned 32-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_u64()
w_u64(
section: string,
field: string,
value: number,
comment?: string): void;Write an unsigned 64-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void
w_u8()
w_u8(
section: string,
field: string,
value: number,
comment?: string): void;Write an unsigned 8-bit integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Section name. |
field | string | Field name. |
value | number | Value to write. |
comment? | string | Optional line comment. |
Returns
void