argholds the pathname of the file containing the program? So we can get the pathname of the directory containing it by chopping off the leafname from the end of that, together with the fullstop that RISC OS uses as the directory separator symbol. The leafname cannot have any fullstops in it. The expression
"%.[^%.]+$"is a pattern that matches text starting with a full stop (%.) followed by a nonempty string that does not contain fullstops [^%.]+ which continues till the end of the text ($). The % is needed because a fullstop by itself matches any single character. So this pattern should match just what we want to chop out. The expression
(arg):gsub ("%.[^%.]+$","")will have as value the pathname of the directory containing our program. The parentheses round arg are needed because arg is an expression (take the value of the table arg at index 0). gsub is the global substitution string method. The expression in front of the colon gives the string it is to be applied to. Its effect is to do a global substitution in the string, replacing each substring that matches the pattern given by its first argument by the value of its second argument (when this is a string). In our case not more than one substring can match, and the effect is to replace the leafname and directory separator by an empty string.