Skip to content

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

ts
new ini_file(): ini_file;

Create an empty ini file.

Returns

ini_file

Constructor

ts
new ini_file(path: string): ini_file;

Open an ini file from the game config path.

Parameters

ParameterTypeDescription
pathstringFile name or path relative to $game_config$.

Returns

ini_file

Remarks

This constructor resolves path below $game_config$.

Constructor

ts
new ini_file(initial: string, path: string): ini_file;

Open an ini file from a filesystem alias and relative path.

Parameters

ParameterTypeDescription
initialstringFilesystem alias, for example $game_config$.
pathstringFile name or path relative to the alias.

Returns

ini_file

Methods

fname()

ts
fname(): string;

Get file name and path of ini file.

Returns

string

Full path to ini file.

Example

ts
`f:\applications\steam\steamapps\common\stalker call of pripyat\gamedata\configs\misc\task_manager.ltx`

line_count()

ts
line_count(section: string): number;

Parameters

ParameterTypeDescription
sectionstringTarget 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()

ts
line_exist(section: Nillable<string>, field: string): boolean;

Check if line exists in the file by section and field.

Parameters

ParameterTypeDescription
sectionNillable<string>Target section to check.
fieldstringSection field to check.

Returns

boolean

Whether line exists.


r_bool()

ts
r_bool(section: string, field: string): boolean;

Read a boolean value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.

Returns

boolean

Parsed boolean value.


r_clsid()

ts
r_clsid(section: string, field: string): number;

Read a class identifier value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.

Returns

number

Parsed class identifier.


r_float()

ts
r_float(section: string, field: string): number;

Read a floating-point value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.

Returns

number

Parsed number.

Throws

If the section or field does not exist.


r_line()

ts
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 ParameterDefault type
T extends stringstring
P extends stringstring

Parameters

ParameterTypeDescription
sectionstringSection name.
line_numbernumberZero-based line index inside the section.
keystringPlaceholder for Lua out parameter.
valuestringPlaceholder 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()

ts
r_s32(section: string, field: string): number;

Read a signed 32-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.

Returns

number

Parsed integer.

Throws

If the section or field does not exist.


r_string()

ts
r_string(section: string, field: string): string;

Parameters

ParameterTypeDescription
sectionstringIni file section.
fieldstringIni 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()

ts
r_string_wb(section: string, field: string): string;

Parameters

ParameterTypeDescription
sectionstringIni file section.
fieldstringIni 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()

ts
r_string_wq(section: string, field: string): string;

Read a quoted string value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.

Returns

string

Parsed string.

Remarks

Uses the same engine reader as r_string_wb; quoted values may keep spaces.


r_token()

ts
r_token(
   section: string, 
   field: string, 
   list: token_list): number;

Read a token value using a token list.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
listtoken_listToken list used for lookup.

Returns

number

Token id.


r_u32()

ts
r_u32(section: string, field: string): number;

Read an unsigned 32-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.

Returns

number

Parsed integer.

Throws

If the section or field does not exist.


r_vector()

ts
r_vector(section: string, field: string): vector;

Read a 3D vector.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.

Returns

vector

Parsed vector.

Throws

If the section or field does not exist.


remove_line()

ts
remove_line(section: string, field: string): void;

Remove ini file section field.

Parameters

ParameterTypeDescription
sectionstringTarget section to modify.
fieldstringTarget section field to remove.

Returns

void


save_as()

ts
save_as(path: string): boolean;

Save this ini file to a path.

Parameters

ParameterTypeDescription
pathstringDestination path.

Returns

boolean

Whether saving succeeded.

Throws

If path is missing.


save_at_end()

ts
save_at_end(should_save: boolean): void;

Adjust saving on file closing/destructor calls.

Parameters

ParameterTypeDescription
should_savebooleanWhether 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()

ts
section_count(): number;

Returns

number

Number of sections in this file.


section_exist()

ts
section_exist(section: Nillable<string>): boolean;

Check whether a section exists.

Parameters

ParameterTypeDescription
sectionNillable<string>Section name.

Returns

boolean

Whether the section exists.


section_for_each()

ts
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

ParameterTypeDescription
cb(this: void, name: string) => voidCallback to call on each ini file section, where name is section name.

Returns

void


set_override_names()

ts
set_override_names(override: boolean): void;

Enable or disable section override name handling.

Parameters

ParameterTypeDescription
overridebooleanWhether override names should be used.

Returns

void

Since

OpenXRay 2017-08-15, 565b39e5


set_readonly()

ts
set_readonly(is_readonly: boolean): void;

Switch the file into readonly or writable mode.

Parameters

ParameterTypeDescription
is_readonlybooleanWhether writes should be disabled.

Returns

void


w_bool()

ts
w_bool(
   section: string, 
   field: string, 
   value: boolean, 
   comment?: string): void;

Write a boolean value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuebooleanValue to write.
comment?stringOptional line comment.

Returns

void


w_color()

ts
w_color(
   section: string, 
   field: string, 
   color: number, 
   comment?: string): void;

Write a packed color value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
colornumberValue to write.
comment?stringOptional line comment.

Returns

void


w_fcolor()

ts
w_fcolor(
   section: string, 
   field: string, 
   color: fcolor, 
   comment?: string): void;

Write a floating-point color value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
colorfcolorValue to write.
comment?stringOptional line comment.

Returns

void


w_float()

ts
w_float(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write a floating-point number.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_fvector2()

ts
w_fvector2(
   section: string, 
   field: string, 
   vector: vector2, 
   comment?: string): void;

Write a 2D vector value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
vectorvector2Value to write.
comment?stringOptional line comment.

Returns

void

Since

OpenXRay 2017-08-15, 565b39e5


w_fvector3()

ts
w_fvector3(
   section: string, 
   field: string, 
   vector: vector, 
   comment?: string): void;

Write a 3D vector value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
vectorvectorValue to write.
comment?stringOptional line comment.

Returns

void

Since

OpenXRay 2017-08-15, 565b39e5


w_fvector4()

ts
w_fvector4(
   section: string, 
   field: string, 
   vector: never, 
   comment?: string): void;

Write a 4D vector value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
vectorneverValue to write.
comment?stringOptional line comment.

Returns

void

Since

OpenXRay 2017-08-15, 565b39e5


w_s16()

ts
w_s16(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write a signed 16-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_s32()

ts
w_s32(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write a signed 32-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_s64()

ts
w_s64(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write a signed 64-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_s8()

ts
w_s8(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write a signed 8-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_string()

ts
w_string(
   section: string, 
   field: string, 
   value: string, 
   comment?: string): void;

Write a string value.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuestringValue to write.
comment?stringOptional line comment.

Returns

void


w_u16()

ts
w_u16(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write an unsigned 16-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_u32()

ts
w_u32(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write an unsigned 32-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_u64()

ts
w_u64(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write an unsigned 64-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void


w_u8()

ts
w_u8(
   section: string, 
   field: string, 
   value: number, 
   comment?: string): void;

Write an unsigned 8-bit integer.

Parameters

ParameterTypeDescription
sectionstringSection name.
fieldstringField name.
valuenumberValue to write.
comment?stringOptional line comment.

Returns

void