gawk: Extension Other Design Decisions

1 
1 C.5.3 Other Design Decisions
1 ----------------------------
1 
1 As an arbitrary design decision, extensions can read the values of
1 predefined variables and arrays (such as 'ARGV' and 'FS'), but cannot
1 change them, with the exception of 'PROCINFO'.
1 
1    The reason for this is to prevent an extension function from
1 affecting the flow of an 'awk' program outside its control.  While a
1 real 'awk' function can do what it likes, that is at the discretion of
1 the programmer.  An extension function should provide a service or make
1 a C API available for use within 'awk', and not mess with 'FS' or 'ARGC'
1 and 'ARGV'.
1 
1    In addition, it becomes easy to start down a slippery slope.  How
1 much access to 'gawk' facilities do extensions need?  Do they need
1 'getline'?  What about calling 'gsub()' or compiling regular
1 expressions?  What about calling into 'awk' functions?  (_That_ would be
1 messy.)
1 
1    In order to avoid these issues, the 'gawk' developers chose to start
1 with the simplest, most basic features that are still truly useful.
1 
1    Another decision is that although 'gawk' provides nice things like
1 MPFR, and arrays indexed internally by integers, these features are not
1 being brought out to the API in order to keep things simple and close to
1 traditional 'awk' semantics.  (In fact, arrays indexed internally by
1 integers are so transparent that they aren't even documented!)
1 
1    Additionally, all functions in the API check that their pointer input
1 parameters are not 'NULL'.  If they are, they return an error.  (It is a
1 good idea for extension code to verify that pointers received from
1 'gawk' are not 'NULL'.  Such a thing should not happen, but the 'gawk'
1 developers are only human, and they have been known to occasionally make
1 mistakes.)
1 
1    With time, the API will undoubtedly evolve; the 'gawk' developers
1 expect this to be driven by user needs.  For now, the current API seems
1 to provide a minimal yet powerful set of features for creating
1 extensions.
1