On Tuesday, March 21, 2017 at 4:04:34 AM UTC+1, Rob 'Commander' Pike wrote: > > No, Go does not have run-time evaluation of Go program source. It is > strictly a compiled language, although there are some (pieces of) > interpreters out there. > > > However, Go 1.8 has plugins <https://tip.golang.org/pkg/plugin/> (on Linux x86-64 at least). A possible way -which can also be used in C, C++, Ocaml, etc...- might be to generate (at *runtime* of your program) some Go code in some *temporary* /tmp/generatedsrc.go file (actually using ioutils/TempFile <https://golang.org/pkg/io/ioutil/#TempFile> to get it), then run (using functions from os/exec <https://golang.org/pkg/os/exec/> package) some compilation command to compile that source into a /tmp/generatedsrc.so shared library plugin, and Open <https://tip.golang.org/pkg/plugin/#Open> that plugin, then Lookup <https://tip.golang.org/pkg/plugin/#Plugin.Lookup> some symbol there and use a type assertion <https://tip.golang.org/ref/spec#Type_assertions> to convert it to some functional value, that could be called later.
I confess that I don't know yet exactly how to do that in a convenient and robust way (you want the compilation of the plugin to be minimal and quick, even if it uses most packages of the main program). I have started using Go only once it had plugins because of that issue. The issue is plugins and packages <https://groups.google.com/forum/#!topic/golang-nuts/IKh1BqrNoxI>. Another issue is what exact compilation command should be used (I suspect that passing -linkshared with -buildmode=plugin to the go build compilation command is needed). I have asked a question about plugins and packages <https://groups.google.com/forum/#!topic/golang-nuts/IKh1BqrNoxI> (you probably don't want the plugin to incorporate all the packages of the main program that it is using). It would be nice if some Go plugin guru could explain more how to do that. Cheers -- Basile Starynkevitch <http://starynkevitch.net/Basile/> (France) -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
