preprocessFileLineNumbers: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) |
Lou Montana (talk | contribs) m (Text replacement - "{{Feature | Warning | " to "{{Feature|warning|") |
||
(4 intermediate revisions by the same user not shown) | |||
Line 29: | Line 29: | ||
where <filename> will be the <name> you set and <linenumber> will be <number> + how many lines it is from the '''#line''' line. If the error happened on the line right under '''#line''' it will add 0 to <number>, if on second line, it will add 1 etc.<br><br> | where <filename> will be the <name> you set and <linenumber> will be <number> + how many lines it is from the '''#line''' line. If the error happened on the line right under '''#line''' it will add 0 to <number>, if on second line, it will add 1 etc.<br><br> | ||
It is possible to use more than one '''#line''' keywords, but it seems having just one at the top for little script is enough to pinpoint position of the error easily. | It is possible to use more than one '''#line''' keywords, but it seems having just one at the top for little script is enough to pinpoint position of the error easily. | ||
{{Feature | | {{Feature|warning|If the file you are loading is not prepared using UTF-8 encoding and contains some characters [[toArray | with codes]] > 127, they might convert incorrectly}} | ||
|s1= [[preprocessFileLineNumbers]] fileName | |s1= [[preprocessFileLineNumbers]] fileName | ||
Line 37: | Line 37: | ||
|r1= [[String]] - file content containing {{hl|#line 1 "aFilename"}} | |r1= [[String]] - file content containing {{hl|#line 1 "aFilename"}} | ||
|x1= < | |x1= <sqf>_string = preprocessFileLineNumbers "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"</sqf> | ||
Result is: <br> | Result is: <br> | ||
Line 44: | Line 44: | ||
........ | ........ | ||
|seealso= [[fileExists ]] [[preprocessFile]] [[loadFile]] [[Function]] [[SQF Syntax]] [[call]] [[spawn]] | |seealso= [[fileExists]] [[preprocessFile]] [[loadFile]] [[Function]] [[SQF Syntax]] [[call]] [[spawn]] [[execVM]] [[PreProcessor Commands]] | ||
}} | }} | ||
{{Note | |||
|user= Killzone_Kid | |||
|timestamp= 20131217134400 | |||
|text= The main difference between [[preprocessFile]] and [[preprocessFileLineNumbers]] is that the latter adds #line keyword to the target file, which allows to log the __LINE__ error happened at and the __FILE__ error happened in.<br> | |||
[[File:PreprocessFile.jpg]] | |||
}} | |||
[[ | |||
{{Note | |||
|user= code34 | |||
|timestamp= 20171104101600 | |||
|text= The #line directive get's removed from the output.<br> | |||
The #line directive get's removed from the output.<br> | |||
So to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:<br> | So to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:<br> | ||
''#define'' DEBUG(sharp,name) sharp##line 0 name<br> | ''#define'' DEBUG(sharp,name) sharp##line 0 name<br> | ||
Line 68: | Line 64: | ||
This way you can have custom filenames in error messages. | This way you can have custom filenames in error messages. | ||
}} | |||
Latest revision as of 21:46, 16 May 2024
Description
- Description:
- Returns the preprocessed content of the given file. The preprocessor is C-like, it supports comments using /* */ and PreProcessor Commands. The preprocessor also adds a default debug entrypoint for compiler at the begining of script: #line 1 "aFilename"
The #line keyword can be used in any script that are not preprocess, or with preprocess script with extra macro to protect reserverd sharp character. The format is:
#line <number> "<name>"
followed by new line. <number> could be only positive integer and <name> could be any name. This will be used only if an error occurs in the script. The error will contain the line: File <filename>, line <linenumber>
where <filename> will be the <name> you set and <linenumber> will be <number> + how many lines it is from the #line line. If the error happened on the line right under #line it will add 0 to <number>, if on second line, it will add 1 etc.
It is possible to use more than one #line keywords, but it seems having just one at the top for little script is enough to pinpoint position of the error easily. - Groups:
- System
Syntax
- Syntax:
- preprocessFileLineNumbers fileName
- Parameters:
- fileName: String - path to the file
- Return Value:
- String - file content containing #line 1 "aFilename"
Examples
- Example 1:
- Result is:
#line 1 "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"
disableserialization;
........
Additional Information
- See also:
- fileExists preprocessFile loadFile Function SQF Syntax call spawn execVM PreProcessor Commands
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Dec 17, 2013 - 13:44 (UTC)
-
The main difference between preprocessFile and preprocessFileLineNumbers is that the latter adds #line keyword to the target file, which allows to log the __LINE__ error happened at and the __FILE__ error happened in.
- Posted on Nov 04, 2017 - 10:16 (UTC)
-
The #line directive get's removed from the output.
So to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:
#define DEBUG(sharp,name) sharp##line 0 name
and add this at the right place in your code
DEBUG(#,"your filename"); This way you can have custom filenames in error messages.
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint: Elite version 1.00
- Operation Flashpoint: Elite: New Scripting Commands
- Operation Flashpoint: Elite: Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: System