But of course the AST can be used for other purposes too - for
instance by someone else that needs it ... in that case a different
strategy is necessary. But you are right I could cache the source
string / and AST as a pair - and just rebuild AST from source if
necessary. But I will need to hang on to the source until ... ?
I think source strings are native lua objects, so just use a weak table to cache this pair (string/AST) is ok. Even if you haven't make this cache, you should also wait lua gc to collect source strings.