Richard Bucker

Embedded Lua and/or tcl in golang

Posted at — Feb 22, 2015

I have been working on an installer based on JSON using golang. ┬áThe two projects are macroinator and installinator. The macroinatorproject is a refactoring of the original installinator project which will make it’s way back into the installinator project very shortly.In both cases the DSL is very loosely based on Puppet’s DSL and implemented in a JSON format.This design comes at the end of a very long argument with myself about the value of DSLs in the first place. I have been researching both Lua and tcl embedded libraries just to see what was involved. On the one-hand the tcl history document describes the justification for the implementation of the tcl language and then goes on to say that Lua might be a better modern choice even though Lua is incomplete in terms of tcl’s scope.Today I was sitting in my car in a parking lot contemplating all things embedded in golang and as I was considering Lua and tcl I waffled back and forth several times. On the one hand tcl and Lua are complete grammars and they implemented with very little C code. Something in the range of 10 to 20K lines of C code. So it is very encouraging from that aspect. Without any specific knowledge it feels like go’s generate tool could be a good fit for implementing either grammar.But then there is the counter argument that if the language is already implemented and it’s just a matter of cross compiling the tools then so be it. Go that way.About the only thing I fall back on is that Go’s static compilation model makes deploying either embedded language as a DSL so much better when executing in a container like rocket or docker. Picol might be a possible option since it is a tcl-like grammar and it’s implemented in go. This might span the gap that I was thinking about such that the commands, verbs, macros, might be expressed and executed in a simpler way. As for Lua, since they just added integer division in the 5.3 release in December 2014 I think tcl/picol is probably the way to go.