> I wonder if it makes sense, to expose more of the interpreter to go.
> E.g.: register a user function or add an action written in go.
>

I had thought about this before, but your comment made me want to try it.
It wasn't actually that hard, so I've added backwards-compatible support
for this now (GoAWK v1.1.0). It works kind of like Funcs() in text/template
or html/template.

You can pass in your Go functions as a map[string]interface{}, and as long
as they take and return bools, numbers, or strings (or []byte) it'll use
reflection to do all the hard work for you. It also supports variadic
functions. Functions defined in AWK with "function foo" take precedence
over Go functions passed in via Funcs (I did this so that passing in
different Funcs doesn't change the behavior of certain AWK scripts). See
more docs under the "Funcs" field here:
https://godoc.org/github.com/benhoyt/goawk/interp#Config

It's kind of a solution in search of a problem right now, but you could use
this to call something simple like strings.Repeat, or something complex
like doing an HTTP request. It was also good to learn more about how to use
the "reflect" package.

Again, feedback welcome.

-Ben

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to