1 The `sourcepath()` function determines the path of the currently executed 2 ucode script file, optionally only the directory portion. 3 4 By specifying the a depth parameter, the owning files of functions further 5 up the call stack can be determined. 6 7 Returns a string containing the path (or directory) of the running ucode 8 source file. 9 10 Returns `null` if the path is indeterminate. 11 12 -- Testcase -- 13 {% 14 let output = render("files/include/level1.uc"); 15 16 // replace dynamic testfiles path with placeholder for stable output 17 output = replace(output, TESTFILES_PATH, "..."); 18 19 print(output); 20 %} 21 -- End -- 22 23 -- File include/level1.uc -- 24 This is the 1st level include. 25 26 {% include("level2.uc") %} 27 -- End -- 28 29 -- File include/level2.uc -- 30 This is the 2nd level include. 31 32 {% include("level3.uc") %} 33 -- End -- 34 35 -- File include/level3.uc -- 36 This is the 3rd level include. 37 38 {% for (let depth in [0, 1, 2, 3]): %} 39 Depth {{ depth }}: 40 Path: {{ sourcepath(depth, false) || "indeterminate" }} 41 Directory: {{ sourcepath(depth, true) || "indeterminate" }} 42 43 {% endfor %} 44 -- End -- 45 46 -- Expect stdout -- 47 This is the 1st level include. 48 49 This is the 2nd level include. 50 51 This is the 3rd level include. 52 53 Depth 0: 54 Path: .../include/level3.uc 55 Directory: .../include 56 57 Depth 1: 58 Path: .../include/level2.uc 59 Directory: .../include 60 61 Depth 2: 62 Path: .../include/level1.uc 63 Directory: .../include 64 65 Depth 3: 66 Path: indeterminate 67 Directory: indeterminate 68 69 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt